GridView排序、分页
protected void gvBookTaxis_RowDataBound(object sender, GridViewRowEventArgs e) { if (gvBookTaxis.PageIndex == 0)//判断是否是从第一页开始 { if (e.Row.RowIndex != -1) //判断GridView控件中是否有值 { int id = e.Row.RowIndex + 1;//将当前行的索引加上一赋值给变量id e.Row.Cells[0].Text = id.ToString();//将变量id的值传给GridView控件的每一行的单元格中 } } else { if (e.Row.RowIndex != -1)//否则就用当前页乘以每页显示条数,再加1 { int id = (gvBookTaxis.PageIndex * 每页显示条数) + e.Row.RowIndex + 1; e.Row.Cells[0].Text = id.ToString(); } } } protected void gvBookTaxis_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvBookTaxis.PageIndex = e.NewPageIndex; gvBookTaxis.DataBind(); }