[转]GridView加序号列(分页时重新排序)

原文地址:http://5ie5.blog.163.com/blog/static/6118899420087314181121/

 

 

 

方法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(); 

}

posted on 2013-09-26 08:47  wiikii  阅读(259)  评论(0)    收藏  举报

导航