Friends, I’m populating a GridView in my asp.net application using following code.
GridView grdExport = new GridView();
DataSet dsRecord = objHelper.gReturnDataSet(CommandType.Text, strSql);
grdExport.DataSource = dsRecord.Tables[0];
grdExport.DataBind();
Now the problem is in immediate window, when I’m checking, I’m getting following result:
?dsRecord.Tables[0].Columns.Count
16
?dsRecord.Tables[0].Rows.Count
37
?grdExport.Rows.Count
37
?grdExport.Columns.Count
0
Please, can anyone tell me why Column count is 0 for grdExport?
GridView.Columns Property
Check this:
If you have more columns to your added columns in your grid then it will show count of those columns which you have added not the auto generated columns.
If you show auto generated columns then it will show 0.
Check this markup:
Now it will Show your result of columns’s count to 1:
//Before adding column to gridview
After Adding column to gridview.