GridView实现自动编号
在GridView的RowDataBound()事件里添加如下代码:
1 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
2 {
3 if (e.Row.RowIndex != -1)
4 {
5 int id = e.Row.RowIndex + 1;
6 e.Row.Cells[0].Text = id.ToString();
7 }
8 }
9
2 {
3 if (e.Row.RowIndex != -1)
4 {
5 int id = e.Row.RowIndex + 1;
6 e.Row.Cells[0].Text = id.ToString();
7 }
8 }
9