【发布时间】:2012-03-22 06:43:22
【问题描述】:
朋友们,我正在使用以下代码在我的 asp.net 应用程序中填充一个 GridView。
GridView grdExport = new GridView();
DataSet dsRecord = objHelper.gReturnDataSet(CommandType.Text, strSql);
grdExport.DataSource = dsRecord.Tables[0];
grdExport.DataBind();
现在问题出现在即时窗口中,当我检查时,我得到以下结果:
?dsRecord.Tables[0].Columns.Count
16
?dsRecord.Tables[0].Rows.Count
37
?grdExport.Rows.Count
37
?grdExport.Columns.Count
0
请问,谁能告诉我为什么 grdExport 的列数为 0?
【问题讨论】:
-
自动生成的绑定列字段不会添加到 Columns 集合中。 Hence the count would be zero
-
如果您想要计数,它将与您分配的源表相同,16
-
@V4Vendetta 非常感谢。我不知道..
-
为网格视图设置 autogeneatedcolumns=true