在GridView.RowDataBound 事件 里添加代码以处理编号的显示,比如如下的代码显示对单元格的操作:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Display the company name in italics.
e.Row.Cells[0].Text = (GridView1.PageIndex * GridView1.PageSize * GridView1.PageIndex + e.Row.RowIndex + 1).ToString();
}
}
在aspx页面用下面语句
<%# (Container.DataItemIndex+1).ToString()%>
<%# GridView1.PageIndex * GridView1.PageSize + GridView1.Rows.Count + 1%>