ASP.NET 分页
示例
ObjectDataSource
如果使用ObjectDataSource,几乎已经为您处理了所有事情,只需告诉GridViewAllowPaging并给它一个即可PageSize。
<asp:GridView ID="gvColors"
runat="server"
DataSourceID="sdsColors"
AllowPaging="True"
PageSize="5">
</asp:GridView>
<asp:SqlDataSource ID="sdsColors"
runat="server"
ConnectionString="<%$ MyConnectionString %>"
SelectCommand="SELECT Color_ID, Color_Name FROM Colors">
</asp:SqlDataSource>手动装订
如果手动绑定,则必须处理该PageIndexChanging事件。只需设置DataSource和,PageIndex然后重新绑定GridView。
<asp:GridView ID="gvColors"
runat="server"
AllowPaging="True"
PageSize="5"
OnPageIndexChanging="gvColors_PageIndexChanging">
</asp:GridView>C#
protected void gvColors_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
gvColors.DataSource= //检索数据源的方法
gvColors.PageIndex= e.NewPageIndex;
gvColors.DataBind();
}VB.NET
Protected Sub gvColors_PageIndexChanging(sender As Object, e As GridViewPageEventArgs)
{
gvColors.DataSource= //检索数据源的方法
gvColors.PageIndex= e.NewPageIndex
gvColors.DataBind()
}
热门推荐
6 送大三祝福语简短
10 经典生日祝福语范文简短
11 男朋友中秋祝福语 简短
12 公司团建周年祝福语简短
13 订婚作文祝福语简短英文
14 感谢朋友的祝福语简短
15 简短有深度的祝福语
16 可爱生日祝福语 简短
17 结婚祝福语简短大气古风
18 拜年同事祝福语大全简短