GridView分页代码简单万能实用
更新时间:2012年12月28日 09:38:13 作者:
GridView在使用.net技术搭建的后台,在商品列表或者是信息列表经常会出现;它的作用在于有效的管理信息,增删改查等等最主要的是还可以实现分页,这一点是无可比靡的,接下来介绍如何使用GridView实现分页,需要了解的朋友可以参考下
复制代码 代码如下:
<asp:GridView ID="GridViewHistory" 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 ID="lb_firstpage" runat="server" onclick="lb_firstpage_Click">首页</asp:LinkButton>
<asp:LinkButton ID="lb_previouspage" runat="server"
onclick="lb_previouspage_Click">上一页</asp:LinkButton>
<asp:LinkButton ID="lb_nextpage" runat="server" onclick="lb_nextpage_Click">下一页</asp:LinkButton>
<asp:LinkButton ID="lb_lastpage" runat="server" onclick="lb_lastpage_Click">尾页</asp:LinkButton>
第<asp:Label ID="lbl_nowpage" 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的数据源绑定事件
您可能感兴趣的文章:
相关文章
.net indexOf(String.indexOf 方法)
字符串的IndexOf()方法搜索在该字符串上是否出现了作为参数传递的字符串,如果找到字符串,则返回字符的起始位置 (0表示第一个字符,1表示第二个字符依此类推)如果说没有找到则返回 -12012-10-10
asp.net 模拟提交有文件上传的表单(通过http模拟上传文件)
通过HTTP模拟GET或POST请求,提交数据到服务端获取响应,比较常见些;但如上传文件到服务端,使用html form当然简单了,而因环境所限有时需要使用模拟方法去提交有附件(文件上传)的表单。2010-02-02
Log4net在.Net Winform项目中的使用实例详解
Log4net是一个流行的日志记录工具,可以帮助开发人员在应用程序中实现高效的日志记录,本文将提供一个详细的分步骤示例,来帮助您在.Net Winform项目中使用Log4net,感兴趣的朋友一起看看吧2023-08-08
ASP.NET Core MVC中使用Tag Helper组件
这篇文章介绍了ASP.NET Core MVC中使用Tag Helper组件的方法,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧2022-02-02
ASP.NET MVC使用typeahead.js实现输入智能提示功能
这篇文章介绍了ASP.NET MVC使用typeahead.js实现输入智能提示功能的方法,文中通过示例代码介绍的非常详细。对大家的学习或工作具有一定的参考借鉴价值,需要的朋友可以参考下2022-09-09


最新评论