GridView添加序号列

来源:互联网 发布:如何评审软件立项 编辑:程序博客网 时间:2024/05/17 01:57

方法1:

添加模板列,如下代码:

                       <asp:TemplateField HeaderText="序号">
                            <ItemTemplate>
                                <%#  Container.DataItemIndex+1   %> 
                            </ItemTemplate>
                        </asp:TemplateField>  

方法2:

在后台的GridView1_RowDataBound()方法添加代码

if (e.Row.RowType == DataControlRowType.DataRow)

{

 int id = e.Row.RowIndex + 1;

e.Row.Cells[0].Text = id.ToString();

}

原创粉丝点击