asp.net 中 GridView 与数据源不匹配问题

来源:百度知道 编辑:UC知道 时间:2024/09/22 13:41:06
我想用GridView控件对数据库中的信息进行分页操作

protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
//设置当前页的索引值
GridView1.PageIndex =e.NewPageIndex ;
//重新绑定GridView控件
GridView1.DataBind();
}

执行一个Button按钮时告诉我数据源不支持服务器端的数据分页!!!
protected void Button1_Click(object sender, EventArgs e)
{
if (this.TextBox1.Text == "" && this.TextBox2.Text == "" && this.TextBox3.Text == "")
{
Response.Write("<script language=javascript>alert('所有信息都不能为空!')</script>");
}
else
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "server=(local);uid=sa;pwd=123456;database=test;";
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "insert into student1 values(" + this.Tex

分页用PagedDataSource类
我原来写的用的是Repeater 你这自己改一下

PagedDataSource pds = new PagedDataSource();
pds.DataSource = ds.Tables[0].DefaultView;
pds.AllowPaging = true;
pds.PageSize = 5;
int pageindex = 0;
//先判断当前页码
if (Request.QueryString["pageindex"] == null)
{
pageindex = 0;
}
else
{
pageindex = Convert.ToInt32(Request.QueryString["pageindex"]);
}
//使用当前页码,为分页超链接赋值。
pds.CurrentPageIndex = pageindex;
if (!pds.IsFirstPage)
{
HyperLink1.NavigateUrl = "Search.aspx?pageindex=0";
HyperLink2.NavigateUrl = "Search.aspx?pageindex=" + (pageindex - 1);
}
else
{
HyperLink4.NavigateUrl = "Search.aspx?pageindex=" + (pds.PageCo