GridView自定义分页
来源:互联网 发布:网络机房设备 编辑:程序博客网 时间:2024/06/11 13:39
在ASP.NET 2.0种提供了GridView控件。该控件的分页比较方便,可以通过在Visual Studio .NET 2005种简单设置即可实现各种分页功能。
1. 默认分页方式
(1) 是否允许分页
GridView的AllowPaging属性。
(2) 每页记录数
GridView的PageSize
(3) 分页导航条形式
GridView的PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。
2. 自定义分页
(1) 当前页
1. 默认分页方式
(1) 是否允许分页
GridView的AllowPaging属性。
(2) 每页记录数
GridView的PageSize
(3) 分页导航条形式
GridView的PagerSettings属性的Mode:Numeric,NextPrevious,NextPreviousFirstLast,NumericFirstLast。
2. 自定义分页
(1) 当前页
<asp:Label ID="LabelCurrentPage" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
Text="<%# ((GridView)Container.NamingContainer).PageIndex + 1 %>"></asp:Label>
(2) 总页数
<asp:Label ID="LabelPageCount" runat="server"
Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
Text="<%# ((GridView)Container.NamingContainer).PageCount %>"></asp:Label>
(3) 首页、上一页、下一页、尾页
<asp:LinkButton ID="LinkButtonFirstPage" runat="server" CommandArgument="First" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">首页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonPreviousPage" runat="server" CommandArgument="Prev" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != 0 %>">上一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonNextPage" runat="server" CommandArgument="Next" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">下一页</asp:LinkButton>
<asp:LinkButton ID="LinkButtonLastPage" runat="server" CommandArgument="Last" CommandName="Page"
Visible="<%# ((GridView)Container.NamingContainer).PageIndex != ((GridView)Container.NamingContainer).PageCount - 1 %>">尾页</asp:LinkButton>
<asp:textbox id="txtNewPageIndex" runat="server" width="20px" text='<%# ((GridView)Container.Parent.Parent).PageIndex + 1 %>' />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />
<asp:linkbutton id="btnGo" runat="server" causesvalidation="False" commandargument="-1" commandname="Page" text="GO" />
注:将上述代码放在GridView的<PagerTemplate></PagerTemplate>
PageIndexChanging事件中加入如下代码
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView theGrid = sender as GridView; // refer to the GridView
int newPageIndex = 0;
if (-2 == e.NewPageIndex) { // when click the "GO" Button
TextBox txtNewPageIndex = null;
//GridViewRow pagerRow = theGrid.Controls[0].Controls[theGrid.Controls[0].Controls.Count - 1] as GridViewRow; // refer to PagerTemplate
GridViewRow pagerRow = theGrid.BottomPagerRow; //GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
//updated at 2006年月日:15:33
if (null != pagerRow) {
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox; // refer to the TextBox with the NewPageIndex value
}
if (null != txtNewPageIndex) {
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1; // get the NewPageIndex
}
}
else { // when click the first, last, previous and next Button
newPageIndex = e.NewPageIndex;
}
// check to prevent form the NewPageIndex out of the range
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
// specify the NewPageIndex
theGrid.PageIndex = newPageIndex;
// rebind the control
// in this case of retrieving the data using the xxxDataSoucr control,
// just do nothing, because the asp.net engine binds the data automatically
}
- gridview实现自定义分页
- 自定义GridView分页模板
- GridView自定义分页
- GridView控件自定义分页
- GridView自定义分页导航
- GridView自定义分页
- GridView自定义分页导航
- GridView自定义分页导航
- GridView 自定义分页
- GridView自定义分页导航
- 自定义GridView分页模板
- GridView自定义分页
- [GridView控件]自定义分页
- gridview 自定义分页
- 自定义GridView分页模板
- gridview自定义分页
- GridView自定义分页
- 自定义GridView分页模板
- 应用--设计模式的原则
- 页面自定义拖拽布局
- CSS2.0中最常用的18条技巧
- 设计模式
- 直线的多边形裁剪及任意多边形互裁剪
- GridView自定义分页
- ORA-01779错误的处理方法(转贴:http://tech.inspiremedia.org/archives/82.html,原作者:charlee)
- 技术与生活
- 使用批处理方式实现文件与文件夹的删除
- Visual C#常用函数和方法集汇总
- win32一次性安装版AP2+Modperl+Mason+TT2+PerlASP
- GoF
- js实现间歇滚动内容
- 在CEGUI中使用layout文件(3)