读书人

求教为 GridView 赋值解决办法

发布时间: 2013-01-25 15:55:29 作者: rapoo

求教为 GridView 赋值



为GridView 赋值:

GridView 都用BoundField 默认建的。

this.GVTheGet.Rows[0].Cells[0].Text = gl.rkdh;
this.GVTheGet.Rows[0].Cells[2].Text = gl.th;
this.GVTheGet.Rows[0].Cells[4].Text = gl.xfdw_dm;
this.GVTheGet.Rows[0].Cells[5].Text = gl.dw_dm;
this.GVTheGet.Rows[0].Cells[6].Text = gl.bz;
this.GVTheGet.Rows[0].Cells[7].Text = gl.sl.ToString();

会报超索引错误。

刚从winfrom转NET,习惯DataGridView 中这样赋值,然后报超索引的错的话,加一个
DataGridView.Rows.Add();
就可以了,但是GridView 貌似没有这个方法,求教怎么赋值啊?
.
C# GridView .Net
[解决办法]
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
var row = e.Row;
row.Cells[0].Text = "a";
row.Cells[1].Text = "b";
row.Cells[2].Text = "c";
row.Cells[3].Text = "d";
}
测试没问题

读书人网 >asp.net

热点推荐