GridView分頁可以通過以下步驟實現:
<asp:GridView ID="GridView1" runat="server" AllowPaging="True" PageSize="10"
OnPageIndexChanging="GridView1_PageIndexChanging">
</asp:GridView>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGridView();
}
}
private void BindGridView()
{
// 從數據源獲取數據
DataTable dt = GetDataFromDataSource();
// 將數據綁定到GridView控件
GridView1.DataSource = dt;
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 設置GridView的當前頁碼
GridView1.PageIndex = e.NewPageIndex;
// 重新綁定數據源
BindGridView();
}
以上就是實現GridView分頁的基本步驟。可以根據需要進行進一步的定制,例如顯示分頁控件、顯示當前頁碼等。