允许Gridview的分页属性在asp.net中给出了一个问题.. [英] Allow paging property of Gridview gives a problem..in asp.net..
问题描述
i可以在.aspx页面上使用gridview ..并使用下面的代码将数据绑定到网格..
我的代码..
cmd =新的SqlCommand(选择用户名,密码,登录部门,con);
SqlDataReader dr22 = cmd.ExecuteReader();
GridView1.DataSource = dr22;
GridView1.DataBind();
和我设置属性允许分页=真的对于gridview它给出了以下错误..
数据源不支持服务器端allow_paging
请帮助
Hi,
i can take gridview on .aspx page..and bind data to the Grid by using bellow code..
my code..
cmd = new SqlCommand("select Username,Password,Department from Login",con);
SqlDataReader dr22 = cmd.ExecuteReader();
GridView1.DataSource = dr22;
GridView1.DataBind();
and i set property "Allow Paging=True" for gridview it gives following error..
"The data source does not support server side allow_paging"
please help
推荐答案
而不是DataReader
,使用DataTable
作为gridview的数据源。
Hi,
instead ofDataReader
, useDataTable
as data source for gridview.
Because You Used Datareader which works in forward only manner.<br />
Use Dataset or Datatable[Dataadpter] which supports both forward and backward navigation.
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
Binddata();
}
}
public void Binddata()
{
string connect=System.Configuration.ConfigurationManager.ConnectionStrings["conn"].ConnectionString;
SqlConnection sqlconn = new SqlConnection(connect);
SqlDataAdapter da = new SqlDataAdapter("select * from persons",sqlconn);
DataSet ds = new DataSet();
da.Fill(ds);
sqlconn.Open();
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
sqlconn.Close();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
Binddata();
}
为什么?您是否尝试过 Google [ ^ ]?
谷歌是你的朋友,请用它来找到你的解决方案。您可以通过互联网找到许多示例。
好的。 让我谷歌为您服务 [ ^ ]。
--Amit
Why? Did you tried Google[^]?
Google is your friend and please use that to find your solution. There are many examples you can find over the internet.
Ok. Let me Google that for you[^].
--Amit
这篇关于允许Gridview的分页属性在asp.net中给出了一个问题..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!