Click here to Skip to main content
15,891,136 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all

My class structure is like:

C#
public class ClassName
{
    public string ColumnName{get;set;}
    public List<string> ColumnValues{get;set;} 
}

list<classname> lstClass=new List<classname>();
// Iterating for values into lstClass
// Now i have values into lstClass</classname></classname></string>


I want to bind a datagrid so that the ColumnName property of class is as Column name of datagrid and below each column ColumnValues property of class.
If there are two lists items in lstClass then structure will be:

ColumnName 1  | ColumnName 2
value1        | value1
value2        | value2


Kindly help in that regard.

Thanks
Piyush
Posted
Updated 17-Jul-11 20:26pm
v2
Comments
Ashika s 18-Jul-11 2:30am    
can u please elaborate your question?
Piyush Nandanwar 18-Jul-11 2:56am    
The ColumnName property of my class should bind to header of datagrid with their respective values(here values are from property ColumnValues of Class)
Piyush Nandanwar 18-Jul-11 2:52am    
The ColumnName property of my class should bind to header of datagrid with their respective values(here values are from property ColumnValues of Class)

You can make the Itemspaneltemplate of the ItemsControl you bind to horizontal.
This should give the desired effect you require.

Something like
XML
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation='Horizontal' />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
 
Share this answer
 
v2
Comments
Piyush Nandanwar 18-Jul-11 2:49am    
do i need to bind a list box inside stack panel to display ColumnValues??
You cannot achieve this directly. Binding a collection normally act as rows and not as columns.

You should maintain the columns in a separate collection bind to the Columns property of the DataGrid.

Mark it as answer if it is helpful.
 
Share this answer
 
Haiiii


gridview.datasource = function for retrieving values;
gridview.databind();
 
Share this answer
 
Comments
Piyush Nandanwar 18-Jul-11 2:48am    
structure of my list to bind a datagrid is different.Please have a look on my question one more time.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900