首页 > 编程 > .NET > 正文

GridView分页代码简单万能实用

2024-07-10 13:23:20
字体:
来源:转载
供稿:网友

复制代码 代码如下:


<asp:GridView runat="server" AutoGenerateColumns="False"
CssClass="vip_table" GridLines="None" BorderStyle="None" CellPadding="0"
ShowHeader="False" AllowPaging="true" PageSize="20"
onpageindexchanging="GridViewHistory_PageIndexChanging">
<PagerTemplate>
<asp:LinkButton runat="server">首页</asp:LinkButton>
<asp:LinkButton runat="server"
onclick="lb_previouspage_Click">上一页</asp:LinkButton>
<asp:LinkButton runat="server">下一页</asp:LinkButton>
<asp:LinkButton runat="server">尾页</asp:LinkButton>
第<asp:Label runat="server" Text="<%#GridViewHistory.PageIndex+1 %>" ForeColor="#db530f"></asp:Label>页/共<asp:Label
ID="lbl_totalpage" runat="server" Text="<%#GridViewHistory.PageCount %>" ForeColor="#db530f"></asp:Label>页
</PagerTemplate>



后台代码:

复制代码 代码如下:


//分页
protected void GridViewHistory_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridViewHistory.PageIndex = e.NewPageIndex;
dataBinding();
}
protected void Button_search_Click(object sender, EventArgs e)
{
dataBinding();
}
protected void lb_firstpage_Click(object sender, EventArgs e)
{
this.GridViewHistory.PageIndex = 0;
dataBinding();
}
protected void lb_previouspage_Click(object sender, EventArgs e)
{
if (this.GridViewHistory.PageIndex > 0)
{
this.GridViewHistory.PageIndex--;
dataBinding();
}
}
protected void lb_nextpage_Click(object sender, EventArgs e)
{
if (this.GridViewHistory.PageIndex < this.GridViewHistory.PageCount)
{
this.GridViewHistory.PageIndex++;
dataBinding();
}
}
protected void lb_lastpage_Click(object sender, EventArgs e)
{
this.GridViewHistory.PageIndex = this.GridViewHistory.PageCount;
dataBinding();
}


dataBinding()为GridViewHistory的数据源绑定事件
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表