GridView自带分页 1总页数 首页 下一页 上一页 尾页 X 页 go 实现方法 .
2015-12-08 14:46
721 查看
在前台GRIDVIEW中添加如下代码
<PagerTemplate>
<table>
<tr>
<td style="text-align: right">
第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" Text="首页"> </asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" Text="上一页"></asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" Text="下一页"></asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page" Text="尾页"></asp:LinkButton>
<asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox>
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO"></asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
后台代码添加如下代码
protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvw = (GridView)sender;
if (e.NewPageIndex < 0)
{
TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex"); int Pa = int.Parse(pageNum.Text);
if (Pa <= 0) { gvw.PageIndex = 0; }
else { gvw.PageIndex = Pa - 1; }
}
else { gvw.PageIndex = e.NewPageIndex; }
GetBind();//你绑定数据的方法
}
<PagerTemplate>
<table>
<tr>
<td style="text-align: right">
第<asp:Label ID="lblPageIndex" runat="server" Text="<%#((GridView)Container.Parent.Parent).PageIndex + 1 %>"></asp:Label>页
共<asp:Label ID="lblPageCount" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageCount %>"></asp:Label>页
<asp:LinkButton ID="btnFirst" runat="server" CausesValidation="False" CommandArgument="First" CommandName="Page" Text="首页"> </asp:LinkButton>
<asp:LinkButton ID="btnPrev" runat="server" CausesValidation="False" CommandArgument="Prev" CommandName="Page" Text="上一页"></asp:LinkButton>
<asp:LinkButton ID="btnNext" runat="server" CausesValidation="False" CommandArgument="Next" CommandName="Page" Text="下一页"></asp:LinkButton>
<asp:LinkButton ID="btnLast" runat="server" CausesValidation="False" CommandArgument="Last" CommandName="Page" Text="尾页"></asp:LinkButton>
<asp:TextBox ID="txtNewPageIndex" runat="server" Text="<%# ((GridView)Container.Parent.Parent).PageIndex + 1%>" Width="20px"></asp:TextBox>
<asp:LinkButton ID="btnGo" runat="server" CausesValidation="False" CommandArgument="-1" CommandName="Page" Text="GO"></asp:LinkButton>
</td>
</tr>
</table>
</PagerTemplate>
后台代码添加如下代码
protected void PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView gvw = (GridView)sender;
if (e.NewPageIndex < 0)
{
TextBox pageNum = (TextBox)gvw.BottomPagerRow.FindControl("txtNewPageIndex"); int Pa = int.Parse(pageNum.Text);
if (Pa <= 0) { gvw.PageIndex = 0; }
else { gvw.PageIndex = Pa - 1; }
}
else { gvw.PageIndex = e.NewPageIndex; }
GetBind();//你绑定数据的方法
}
相关文章推荐
- Django笔记教程:四、会话、注册、以及用户
- mongorestore 恢复mongodump文件报BSONObj size: 17794400 (0x10F8560) is invalid. Size must be between 0 and
- flowplayer设置视频logo
- self,super,protocol,category,extension 的用法
- Objc-C 知识点回顾 八 NSDate、 Extension、Category、Delegate
- Gosn的使用
- FakeID签名漏洞分析及利用(Google Bug 13678484)
- Firefox失去了Google一年3亿美金的搜索授权费
- TiDB安装make时报错:unrecognized import path "golang.org/x/tools/go/gcimporter"和unrecognized import path "golang.org/x/tools/go/types"
- Django 之更改密码加密类型
- TiDB安装make时报错:unrecognized import path "golang.org/x/tools/go/gcimporter"和unrecognized import path "
- MIGO时没发料不允许入库
- 11 类别(category)和扩展(extension)
- UVALive 6835 Space Golf(物理题)
- Concurrency In Golang
- 每次使用都要去Google的基础知识--.lib与.dll
- 每次使用都要去Google的基础知识--.lib与.dll
- HD 1533 Going Home(最小费用最大流模板)
- Category和Protocol笔记 by STP
- [Golang] groupcache的简单例子