GridView分页的实现 ASP.NET c#(转)特好用
2013-07-08 17:14
288 查看
要在GridView中加入
//实现分页
AllowPaging="true"
//一页数据10行
PageSize="10"
// 分页时触发的事件
OnPageIndexChanging="gvwDesignationName_PageIndexChanging"
在服务器事件里
Code
protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 得到该控件
GridView theGrid = sender as GridView;
int newPageIndex = 0;
if (e.NewPageIndex==-3)
{
//点击了Go按钮
TextBox txtNewPageIndex = null;
//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//得到text控件
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}
if ( txtNewPageIndex!= null)
{
//得到索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
//点击了其他的按钮
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
//得到新的值
theGrid.PageIndex = newPageIndex;
//重新绑定
bingDesignatioonName();
}
//实现分页
AllowPaging="true"
//一页数据10行
PageSize="10"
// 分页时触发的事件
OnPageIndexChanging="gvwDesignationName_PageIndexChanging"
在服务器事件里
Code
protected void gvwDesignationName_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
// 得到该控件
GridView theGrid = sender as GridView;
int newPageIndex = 0;
if (e.NewPageIndex==-3)
{
//点击了Go按钮
TextBox txtNewPageIndex = null;
//GridView较DataGrid提供了更多的API,获取分页块可以使用BottomPagerRow 或者TopPagerRow,当然还增加了HeaderRow和FooterRow
GridViewRow pagerRow = theGrid.BottomPagerRow;
if (pagerRow != null)
{
//得到text控件
txtNewPageIndex = pagerRow.FindControl("txtNewPageIndex") as TextBox;
}
if ( txtNewPageIndex!= null)
{
//得到索引
newPageIndex = int.Parse(txtNewPageIndex.Text) - 1;
}
}
else
{
//点击了其他的按钮
newPageIndex = e.NewPageIndex;
}
//防止新索引溢出
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= theGrid.PageCount ? theGrid.PageCount - 1 : newPageIndex;
//得到新的值
theGrid.PageIndex = newPageIndex;
//重新绑定
bingDesignatioonName();
}
相关文章推荐
- ASP.NET实现24小时实时天气预报(C#)
- ASP.NET(C#)实现一次性上传多张图片(多个文件)
- ASP.NET(c#)实现防止同一用户同时登陆
- asp.net(c#)实现从sql server存取二进制图片
- asp.net C#实现下载文件的六种方法实例
- Asp.net 2.0 C#实现压缩/解压功能 (示例代码下载)
- 在ASP.NET下实现数字和字符相混合的验证码(C# Code)
- [ASP.NET教程] C#中如何实现数据拖动?(拖动图片,到TextBox,并显示)
- Asp.net(c#)实现多线程断点续传
- C#设计模式之Template模板方法模式实现ASP.NET自定义控件 密码强度检测功能
- C# ASP.NET 最常用的通用权限的3个方法例子展示(每个功能一行代码实现)
- [导入]Asp.net 2.0 C#实现压缩/解压功能 (示例代码下载)
- Asp.net(C#) windows 服务{用于实现计划任务,事件监控等}
- asp.net(c#) RSS功能实现代码
- asp.net(C#)中实现身份模拟(转贴)
- ASP.NET中运用xmlhttp实现无刷新数据传递(C# and JavaScript)
- asp.net/c# 用<input type="file" />实现文件上传,multipart/form-data
- Asp.net(c#)实现多线程断点续传
- 长内容自动分页的实现 (asp.net C#)