Grid View Pagination

烈酒焚心 提交于 2019-12-12 05:08:37

问题


I have a GridView, 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 approaches?


回答1:


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




回答2:


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



来源:https://stackoverflow.com/questions/1248447/grid-view-pagination

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!