data source does not support server-side data paging uisng asp.net Csharp

Posted by Aamir Hasan on ASP.net Weblogs See other posts from ASP.net Weblogs or by Aamir Hasan
Published on Fri, 30 Apr 2010 15:17:00 GMT Indexed on 2010/04/30 15:28 UTC
Read the original article Hit count: 857

Filed under:
|

Yesterday some one mail me and ask about data source does not support server side data paging.So i write the the solution here please if you have got this problem read this article and see the example code this will help you a Lot.The only change you have to do is in the DataBind().Here you have used the SqlDataReader to read data retrieved from the database, but SqlDataReader is forward only. You can not traverse back and forth on it.
So the solution for this is using DataAdapter and DataSet.
So your function may change some what like this


private void DataBind()
{
//for grid view
SqlCommand cmdO;
string SQL = "select * from TABLE ";
conn.Open();
cmdO = new SqlCommand(SQL, conn);
SqlDataAdapter da = new SqlDataAdapter(cmdO);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.Visible = true;
GridView1.DataSource = ds;
GridView1.DataBind();
ds.Dispose();
da.Dispose();
conn.Close();

}



This surely works. The reset of your code is fine. Enjoy coding.

© ASP.net Weblogs or respective owner

Related posts about ASP.NET

Related posts about gridview