0

I am in the situation of working with large amount of records in a grid. Instead of, binding all records into the grid. why we should not bind set of records which are belongs to 5th page.

4
  • 3
    There are many, many examples of paging for grids on the internet. Perhaps a search on a famous search engine will lead you in the right direction. Commented Jun 23, 2009 at 13:36
  • If you tell us more precisely what you are looking for (code, theory, etc.) we may be able to give you some answers. Commented Jun 23, 2009 at 13:38
  • Sadly, may examples I've seen of paging put an entire DataSet into ViewState. Keep looking if yuo see that - there are some clever stored-proc ideas that take page#/sort-col info as arguments. Commented Jun 23, 2009 at 13:49
  • your solution to this problem worked out well in my case. thank you Commented Oct 1, 2009 at 6:22

2 Answers 2

2

You can enable paging on your GridView by setting AllowPaging to true and PageSize to the number of records you wish to display per page.

The advantage of paging is that you can bind the full data source to your GridView and allow the user to move between pages, it's much less programming on the server side to always work with the full data source.

EDIT:

It is also recommended that you don't put the entire dataset in the GridView view state, a better option would be to cache the data and rebind in the Page Load

Sign up to request clarification or add additional context in comments.

1 Comment

Not to mention that if you use the OnRowDataBound event, only items for the current page will be binded, so you don't have too much work to do.
2

As a good practice one should not bind all the records retrieved from a query directly to a control such as grid view , unless of course you are absolutely sure that the number of records are few.

This is because when the number of records are huge, the page loads slower,since binding takes a lot of time.

One approach that I have used in my previous project is to fetch the total number of records affected by the query. (Lets say they are 1000).

I then divide the number of records with the page size (say 100).

So now I provide pagination with pages (1-10).

When the user clicks on a particular page, I fetch records pertaining to that page using ROW_NUMBER() function in SQL.

The query will be something like

SELECT x, y, ROW_NUMBER() OVER(ORDER BY z asc) AS 'RowNumber' FROM t WHERE RowNumber > lowerlimit and RowNumber < upperlimit. 

Lowerlimit and upperlimit are calculated using the current page number and page size.

I hope this answers your question

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.