.NET中GRIDVIEW数据源不支持服务器端的分页,请教高手呀!紧急 10
我的GridView中设置了AllowPaging为TRUE同时分页代码如下protectedvoidGridView1_PageindexChanging(object...
我的GridView中设置了 AllowPaging为TRUE同时分页代码如下
protected void GridView1_PageindexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
conn.Open();
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataReader dr = comm.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
不知道有什么问题啊,请教高手! 展开
protected void GridView1_PageindexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
conn.Open();
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataReader dr = comm.ExecuteReader();
GridView1.DataSource = dr;
GridView1.DataBind();
}
不知道有什么问题啊,请教高手! 展开
6个回答
展开全部
DataReader不支持分页,使用DataSet
protected void GridView1_PageindexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
BindData();
}
private void BindData()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
protected void GridView1_PageindexChanging(object sender, GridViewPageEventArgs e)
{
this.GridView1.PageIndex = e.NewPageIndex;
BindData();
}
private void BindData()
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
GridView1.DataSource = ds.Tables[0].DefaultView;
GridView1.DataBind();
}
本回答被网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
SqlDataReader是只能向前的记录集 SqlDataReader不支持分页 改为DataSet就行
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
conn.Open();
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;;
GridView1.DataBind();
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=172.1.21.78;Initial Catalog=FamilyFinanceSystem;Integrated Security=TRUE";
conn.Open();
SqlCommand comm = new SqlCommand("Select * from rdParentItem", conn);
SqlDataAdapter da = new SqlDataAdapter(comm);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0].DefaultView;;
GridView1.DataBind();
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
sqlDataReader 不能支持自动分页,但能支持自定义分页
你绑定的数据源可以试着用DataTable 或者DataSet就可以了
你绑定的数据源可以试着用DataTable 或者DataSet就可以了
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
我记得不是自动分页的吗?服务端的GridView直接用控件拖进去嘛,不用自己写代码的,
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
这个事件里面只写this.GridView1.PageIndex = e.NewPageIndex;
下面的绑定数据的代码放到外面去 在页面加载时调用一下下面的代码
下面的绑定数据的代码放到外面去 在页面加载时调用一下下面的代码
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询