设置gridview headertext报错
设置gridview headertext出错
最后一行 报错:其他信息: 索引超出范围。必须为非负值并小于集合大小。
数据取出来没问题 。不手动绑定headertext的话 数据能出来。
应该怎么解决
------解决方案--------------------
其实你可以写select 语句时把列名定好。比如你第一列是id,你就select id as ‘序号’ from。。。。
然后数据集取到的数据显示在GridView上就万事大吉了。列名不需要重新设置了
------解决方案--------------------
在Professional SharePoint 2010 Development这本书的第219页上有个例子,是先设置HeaderText,然后绑定

SqlDataAdapter daAll = new SqlDataAdapter(sqlAll, conn);
DataSet dsAll = new DataSet();
daAll.Fill(dsAll);
this.GridView1.DataSource = dsAll.Tables[0].DefaultView;
this.GridView1.AutoGenerateColumns = false;
this.GridView1.DataKeyNames = new string[] { "Id" };
this.GridView1.Columns[0].HeaderText = "序号";
最后一行 报错:其他信息: 索引超出范围。必须为非负值并小于集合大小。
数据取出来没问题 。不手动绑定headertext的话 数据能出来。
应该怎么解决
------解决方案--------------------
其实你可以写select 语句时把列名定好。比如你第一列是id,你就select id as ‘序号’ from。。。。
然后数据集取到的数据显示在GridView上就万事大吉了。列名不需要重新设置了
------解决方案--------------------
在Professional SharePoint 2010 Development这本书的第219页上有个例子,是先设置HeaderText,然后绑定