GridView里的分页功能 5
///<summary>///分页的数据绑定的方法///</summary>///<returns></returns>publicPagedDataSourcepage...
/// <summary>
/// 分页的数据绑定的方法
/// </summary>
/// <returns></returns> public PagedDataSource pageshow()
{
SqlConnection conn = new SqlConnection("Data Source=CX;Initial Catalog=wushui;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from experiment", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "exp");
PagedDataSource ps = new PagedDataSource();
ps.AllowPaging = true;//允许分页
ps.PageSize = 3;//单页的项数
ps.CurrentPageIndex = num;//当前页的索引,num初始为0
ps.DataSource = ds.Tables[0].DefaultView;
return ps;
}
//删除键
SqlConnection conn = new SqlConnection("Data Source=CX;Initial Catalog=wushui;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("delete from experiment where ename='" + this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString() + "'", conn);
cmd.ExecuteNonQuery();
conn.Close();
this.GridView1.DataSource = pageshow();
this.GridView1.DataBind();
当我把GridView单页的行都删除后,就会报错
错误:索引 3 不是为负数,就是大于行数。
求解,万分感谢 展开
/// 分页的数据绑定的方法
/// </summary>
/// <returns></returns> public PagedDataSource pageshow()
{
SqlConnection conn = new SqlConnection("Data Source=CX;Initial Catalog=wushui;Integrated Security=True");
SqlDataAdapter sda = new SqlDataAdapter("select * from experiment", conn);
DataSet ds = new DataSet();
sda.Fill(ds, "exp");
PagedDataSource ps = new PagedDataSource();
ps.AllowPaging = true;//允许分页
ps.PageSize = 3;//单页的项数
ps.CurrentPageIndex = num;//当前页的索引,num初始为0
ps.DataSource = ds.Tables[0].DefaultView;
return ps;
}
//删除键
SqlConnection conn = new SqlConnection("Data Source=CX;Initial Catalog=wushui;Integrated Security=True");
conn.Open();
SqlCommand cmd = new SqlCommand("delete from experiment where ename='" + this.GridView1.Rows[e.RowIndex].Cells[0].Text.ToString() + "'", conn);
cmd.ExecuteNonQuery();
conn.Close();
this.GridView1.DataSource = pageshow();
this.GridView1.DataBind();
当我把GridView单页的行都删除后,就会报错
错误:索引 3 不是为负数,就是大于行数。
求解,万分感谢 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询