GridView1_RowDataBound

来源:百度知道 编辑:UC知道 时间:2024/09/21 01:35:54
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
string e0 = e.Row.Cells[0].Text;//年
string e1 = e.Row.Cells[1].Text;//月
string e2 = e.Row.Cells[2].Text;//姓名
string e18 = e.Row.Cells[18].Text;
string e19 = e.Row.Cells[19].Text;
怎么理解上述代码的功能呢?

RowDataBound
是在给GridView绑定完数据后触发的 就是说数据绑定完了 但是需要做一些调整 就可以在这里做操作
string e0 = e.Row.Cells[0].Text;//年
说一个你就明白了
声明一个字符串便林 e0
e就是protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 这个参数 GridViewRowEventArgs 这个对象是为事件提供数据用的 也就是说e现在就是GridView里面的整个数据的集合
e.Row row就是指行对象 就是GridView中的行
e.Row.Cells[0] Cells 就是列对象 就是GridView中的一列 Cells[0]表示第一列(跟数组一样 是从0开始标记的)
e.row.Cells[0].Text Text 该列的内容(你应该明白的)
其实GridView在绑定的时候是一个循环 所以 这个事件也是一遍一遍的循环的
string e0 = e.Row.Cells[0].Text;//年
string e1 = e.Row.Cells[1].Text;//月
string e2 = e.Row.Cells[2].Text;//姓名
string e18 = e.Row.Cells[18].Text;
string e19 = e.Row.Cells[19].Text;
就是得到第1,2,3,19,20列的指 分别赋给变量
我觉得这么做除了测试 没别的用 一般在这里都是对绑定的数据做处理的 比如某列是姓名字段 在数据库是0和1 0是男性 1是女性 那么在这里就可以判断(比如是第一列) if(e.Row.Cells[0].Text=="0"){e.Row.Cells[0].Text="男";}else{e.Row.Cells[0].Text="女";}
LZ明白了吧~!

protected void GridView1_RowDataBo