1.GridView添加序号列 每一页不重新开始 接上页
<asp:TemplateField HeaderText="序号"> <ItemTemplate> <%# Container.DataItemIndex+1 %> </ItemTemplate> </asp:TemplateField>
2.每一页从1开始
Code
protected void GV_showAll_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowIndex > -1)
{
e.Row.Cells[0].Text = (e.Row.RowIndex+1).ToString() ;
//或者e.Row.Cells[0].Text = e.Row.DataItemIndex;
}
}
前台模板列为空
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
</ItemTemplate>
</asp:TemplateField>
或者
<asp:TemplateField HeaderText="序号">
<ItemTemplate>
<%#Container.DisplayIndex +1%>
</ItemTemplate>
</asp:TemplateField>