利用普通的按钮实现gridview的分页问题!
来源:互联网 发布:淘宝怎么注销实名认证 编辑:程序博客网 时间:2024/06/08 07:29
这是一个完整的代码!希望他能让你们更好的明白 gridview分页的问题! 重要的地方都有注释!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class pagepart : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BingStudent(); 这是我们定义的一个方法,用它调出我们数据库中的数据!
}
}
private void BingStudent()
{
string str = @"Server=.\SQLEXPRESS;integrated security=sspi;Initial catalog=student;"; 链接数据库的字段
DataSet ds = new DataSet(); 创建一个数据集用来存放我们的数据!
using (SqlConnection sqlcnn = new SqlConnection(str))
{
SqlCommand sqlcmm = sqlcnn.CreateCommand();
sqlcmm.CommandText = "select * from net3";
SqlDataAdapter da = new SqlDataAdapter(sqlcmm);
da.Fill(ds);
}
this.GridView2.DataSource = ds.Tables[0]; 用gridview来绑定我们的数据!
this.GridView2.DataBind();
}
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e) 这个事gridview的RowDataBound事件,我们可以用来来显示我们浏览的当前页,和总共的页数!
{
if (e.Row.RowType == DataControlRowType.Pager) 判定是不是在我们的数据行里!
{
(e.Row.Cells[0].FindControl("Label1") as Label).Text = (GridView1.PageIndex + 1).ToString() + "/" + GridView1.PageCount; 显示页数!当前页/总共页
//(e.Row.Cells[0].FindControl("Label1") as Label).Text ="第̨²"+ (GridView1.PageIndex + 1).ToString() + "页°3;ê?共2" + GridView1.PageCount+"页°3";
}
}
protected void LinkButton5_Click(object sender, EventArgs e) //这个是我们自定义的按钮,在这里是 第一页!
{
this.GridView2.PageIndex = 0;
BingStudent();
}
protected void LinkButton6_Click(object sender, EventArgs e) //这个是我们自定义的按钮,在这里是 上一页!
{
int index = this.GridView2.PageIndex;
if (index >= 1)
{
index--;
}
this.GridView2.PageIndex = index;
this.BingStudent();
}
protected void LinkButton7_Click(object sender, EventArgs e) //这个是我们自定义的按钮,在这里是 最后页!
{
this.GridView2.PageIndex = this.GridView2.PageCount - 1;
this.BingStudent();
}
protected void LinkButton8_Click(object sender, EventArgs e) //这个是我们自定义的按钮,在这里是 下一页!
{
int index = this.GridView2.PageIndex;
if (index < this.GridView2.PageCount + 1)
{
index++;
}
this.GridView2.PageIndex = index;
this.BingStudent();
}
}
- 利用普通的按钮实现gridview的分页问题!
- Gridview的分页问题
- GridView实现的分页
- GridView分页的实现
- GridView分页的实现
- GridView分页的实现
- 关于GridView的分页问题
- GridView 的DropDownList分页实现
- GridView 的DropDownList分页实现
- GridView利用分页存储过程实现真正的自定义分页查询
- 关于GridView查询后分页的问题
- GridView的分页和按列头排序问题?
- asp.net2.0分页的实现(GridView)
- 使用ObjectDataSource实现GridView的高效分页
- ObjectDataSource实现GridView的分页总结
- GridView无刷新分页的实现(ICallBackEventHandler)
- GridView控件自定义分页的实现
- GridView无代码分页排序的实现
- LCD驱动调试
- 判断点是否在多边形中 射线判断法
- UIWebView获取网页的标题
- The C10K problem
- 实现风格转换页面
- 利用普通的按钮实现gridview的分页问题!
- 函数指针与指针函数
- (转,好文必须的)Android深入浅出之Binder机制
- JAVA面试题
- GridView中使用存储过程分页
- 字符串常量和指针
- zen-cart基本操作手册(二次开发手册)
- 利用 JAVA 操作 EXCEL 文件
- intellij idea教程