views:

232

answers:

2

Dear All, I have a grid view and I want to implement Pagination functionality.This is working fine.

 protected DataSet FillDataSet()
{
    string source = "Database=GridTest;Server=Localhost;Trusted_Connection=yes";
    con = new SqlConnection(source);
    cmd = new SqlCommand("proc_mygrid", con);
    ds = new DataSet();
    da = new SqlDataAdapter(cmd);
    da.Fill(ds);
    GridView1.DataSource = ds;
    GridView1.DataBind();
    return ds;


}
 protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
   int newPagenumber = e.NewPageIndex;
   GridView1.PageIndex = newPagenumber;
   GridView1.DataSource = FillDataSet();
   GridView1.DataBind();

}

But the problem is for each pagination I have to call FillDataSet(); Is there any way to stop that.Any other coding approach? Thanks.

+1  A: 

Have a look at Scott Mitchell's article: Custom Paging in ASP.NET 2.0 with SQL Server 2005.

If you're using a version of SQL Server pre-2005, then try: A More Efficient Method for Paging Through Large Result Sets

Mitch Wheat
A: 

You could also consider using LINQ To SQL as it makes it easy to implement server-side pagingation.

Dan Diplo