3

If a procedure returns 5000 (Five Thousand) rows and I want bind it with a Asp.net Grid View. Neither it won’t be good approach to call all the rows and bind it with grid and then on grid view Pageindex see all the data or this approach to strike the DB at each Pageindex change. So can anybody give me good answer.

radu florescu
  • 4,315
  • 10
  • 60
  • 92
codery2k
  • 79
  • 3
  • 11

2 Answers2

3

Normally your GridView is only presentation. So you only have to query the correct page to display in the GridView. If you go the the next page you query the db for the next page.

This article will give you directions on how to do this with a datasource:

MSDN - Tutorial 25: Efficiently Paging Through Large Amounts of Data

Efficient Server Side Paging with the ASP.NET GridView Control

Peter
  • 27,590
  • 8
  • 64
  • 84
-1
Session["dt"] = DataTable; //after you get table from procedure, assign it to session

Then in pageload, every time bind grid view to datatable saved in session, you call it from DB just first time

 protected void Page_Load(object sender, EventArgs e)
        {
            GridView.DataSource = Session["dt"];
            GridView.DataBind();
        }
el ninho
  • 4,183
  • 15
  • 56
  • 77
  • 3
    It might be worth to point out that storing large objects in the session is not one of the best practices. – aleafonso Jan 26 '12 at 11:01
  • I wonder if you ever tried storing such a large ammount of data in session. – radu florescu Jan 26 '12 at 11:04
  • 2
    If your result-set takes up 500K and you have 100 users using the application you are looking at 50MB of memory being chewed up on the server with just this practice alone... – Mantorok Jan 26 '12 at 11:08
  • 1
    table with 5000 rows is not large amount of data. – el ninho Jan 26 '12 at 11:10
  • aleafonso i think your are right.. it won't be good approach to store very huge amount of data... lets say its more than 60K rows then this approach will fail.. – codery2k Jan 27 '12 at 11:58