Click here to Skip to main content
15,888,351 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
In my code am using one datagrid , I need to align the coloumns of that datagrid.

DataGrid dgAccount = new DataGrid();
dgAccount .DataSource = dtaccount; //datatable
dgAccount .DataBind();

But the problem here is am getting the count of columns in my datagrid as zero.But data is there in datable. And am able to display that data but the count of column is zero.
Anybody have any idea about this ?
Posted
Comments
_Amy 20-Jun-13 4:06am    
Where you are creating DataGrid? Which event?

try as bellow
DataGrid dg = new DataGrid();

dg.Items.Count; //Number of Items...i.e. Rows;
dg.Items[0].Cells.Count; //Number of columns for that Items
 
Share this answer
 
Try this,

int columnCount = ((DataTable)this.dataGrid.DataSource).Columns.Count;
 
Share this answer
 

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