1
GridView增加自动编号列
2
然后在 GridView 的 RowDataBound 事件中,设定每一列的 lblNo 的 Text 属性值为 RowIndex+1。
因为 RowIndex 起始编号为 0 ,故每列的自动编号为 RowIndex+1。
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim oLabel As Label If e.Row.RowType = DataControlRowType.DataRow Then oLabel = CType(e.Row.Cells(0).FindControl("lblNo"), Label) oLabel.Text = (e.Row.RowIndex + 1).ToString() End If End Sub Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound Dim oLabel As Label If e.Row.RowType = DataControlRowType.DataRow Then oLabel = CType(e.Row.Cells(0).FindControl("lblNo"), Label) oLabel.Text = (e.Row.RowIndex + 1).ToString() End IfEnd Sub
以上的写法遇到 GridView 分页时,都是由 1 开始编号,若需分页需要接续编号,可改用修改如下。
GridView1.RowDataBound Handles System.Web.UI.WebControls.GridViewRowEventArgs) As e ByVal Object, sender GridView1_RowDataBound(ByVal Sub 1 Protected>2 Dim oLabel As Label Di...[
查看详细内容..]
2008-02-20 19:04:58
评论(0)