Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
Can anybody please help in filling a gridview in asp.net from a dataset or datatable or datareader fetching huge data from database and allowing the gridview to have paging option and binding the gridview with the amount of data displayable per page and not binding all the data together. Binding the data to the gridview according to the amount of data shown in per page using paging in gridview. Can anybody please help with the entire code for it.

Thank You.
Posted
Updated 24-Aug-12 8:55am
v2
Comments
[no name] 24-Aug-12 14:39pm    
And what? You want someone to write up all this code for you?
sam_roy 24-Aug-12 15:14pm    
no i want the idea to do it. need a guidance to solve it.
R. Giskard Reventlov 24-Aug-12 14:58pm    
No one will give you the 'entire code'. Why should they? What have you done so far? Note that loading a huge amount of data is a very bad idea.

Start Display Large Amount of Data in GridView with Search Functionality[^].

If only you'd taken a couple of minutes to explore CP you'd see there are few articles that might help.
 
Share this answer
 
Comments
sam_roy 24-Aug-12 15:05pm    
its quite complicated i was looking for a very simple and basic example that will fetch data as per page size and bind that to the gridview not all the data at the sametime. a very simple example. thanks mark i am looking at it. but i would like to have a very basic example implementing the desired functionality.still thanks
R. Giskard Reventlov 24-Aug-12 15:40pm    
You have to read, understand and adapt. There is little chance you'll find precisely what you are looking for.
sam_roy 25-Aug-12 2:04am    
ok mark i appreciate ur help. thanks
You are right, get only the data you need instead of all data.

Paging is fine but when it comes to millions of records, be sure to fetch the required subset of data only.

You can provide the record number start with and the maximum records to retrieve from that starting point. This enables you to retrieve only a subset of records from the datasource based on the current page index. All you need is to keep track of the the current record index.

You can store the record index in viewstate or in hidden fields run at = server.

So, while you first load, set the pageindex to 0 and say you display 20 records.
When the next is clicked, update the page index (pageindex++).
Say when you click 8th page, set the page index to 8 and so on.

Now, when you fetch the record from database, pull the data for pageindex 8.
To get the record number,
fromrecord = pageindex*displayrecordno
torecord = fromrecord+displayrecordno

In the e.g. displayrecordno=20

I would prefer reader than datatable and dataset as reader is faser than the other two.

Hope this helps.
cheers
 
Share this answer
 
Comments
sam_roy 24-Aug-12 15:10pm    
thank u sandip. can u provide me a bit of coding for it. and one more question if i fetch the entire data at a time in dataset or datatable for close connection work. then try to implement the functionality of displaying say 10 data per page and binding that amount of data from data table or dataset(i.e row 0 to 9 for pageindex1 and then 10 to 19 row number from dataset for page index 2 like that). is it possible?
Sandip.Nascar 24-Aug-12 15:32pm    
Yes the second one is also possible. This is how grid view works. It takes the data in page_load and then use the page index to paginate.

But when comes for millions of record, not a good approach to get the data in whole bunch.

You write sql statement to get the row_number and use the rowid to populate data from table.

Row_number() OVER (ORDER BY ...)
Thus you get the row number and using it you can fetch only the records you want, say from 1 to 10, 71 to 80 and so on...

You can also have a look into the links to get a complete idea of gridview
http://www.codeproject.com/Articles/36528/GridView-all-in-one

cheers

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900