|
|
||||||
|
#1
|
|
|
|
|
Hi all,
Can anyone tell me what exactly VirtualItemCount in datagrid. I read on msdn but not clear about it. Any help will be truely appreciared. thanks in advance |
|
|
|
#2
|
|
|
|
|
Hi there,
Imagine you want to display a pager below a datagrid in order to allow users to navigate through data query results returned from database. In 99% applications results are displayed in paged form, meaning user is presented with a small chunk of results, i.e. search result returned 1350 records, but due to several reasons (perfomance, user experience, etc.) your list shows only 10 records at time. I believe you know all that. DataGrid has got built in mechanism for paging which is based on entire result set assigned to datagrid's datasource property. It requires all the records to be included in paging, which means if you wanted to display only 10 records in 10th page from your result set (records from 91 to 100) you would have to fetch entire result set (1350 rows) locally (transfer all the records from database to local's machine memory). As you can guess it is very inefficient. Therefore, developers invented much better techniques (custom paging) allowing fetching required information only . Most of them require page number (or start row index) and page size (or end row index), but please note to display pager properly (i.e. show/hide next page button) you have to know how many rows (pages) are within result set (i.e. query returned 1350 rows, current page = 2, you should show previous and next buttons because you know there are records before and after as number of matching records is 1350). And here comes virtualitemcount property which holds total number of rows matching criteria, which in this case would be 1350. I know it might sound difficult, but it's easire to understand it on real life example presented by one of this asp.net community guys Peter Bromber: http://www.eggheadcafe.com/articles/20060109.asp Hope this helps |
|
#3
|
|
|
|
|
Hi,
thanks for your reply. but still i have one confusion regarding virtualitemcount. Does navigation bar displayed at the bottom of datagrid showing page number depends on virtualitemcount? Does it means i need to set virtualitemcount to total number of records which present in table which i am displaying page by page into datagrid? if yes then does it means that every time going from one page to another i need to fire query into database passing current page index and retrieving those many records from database according to page size? Please correct me if i am wrong. thanks in advance. |
|
#4
|
|
|
|
|
Hi there Archana,
Howdy. Seems you got it right but you're missing relationship between all the variables (especially virtualitemcount - pagecount). Let's analyse a real life example. PageSize = 10 (number of records being displayed in datagrid control at once) VirtualItemCount = 35 (number of records matching criteria) Case 1. First page is selected (CurrentPageIndex = 0) Total number of pages: PageCount = (VirtualItemCount+PageSize - 1) / PageSize = (35 + 10 - 1) / 10 = 4 so the data grid should look like this: 1. | blabla | 2. | blabla | 3. | blabla | ..... 10. | blabla | [1] 2 3 4 > as you can see, virtualitemcount = 35 so you may display buttons pages 2,3,4. Because this is the first page you cannot move to previous page (< button is invisible) Case 2. Now we moved to second page. 11. | blabla | 12. | blabla | 13. | blabla | ..... 20. | blabla | < 1 [2] 3 4 > There are 4 pages, 2nd is currently selected, we can display prev/next buttons as there are records before and after. Case 3. And finally we selected last page 31. | blabla | 32. | blabla | 33. | blabla | 34. | blabla | 35. | blabla | < 1 2 3 [4] VirtualItemCount literally represents the last item index. > if yes then does it means that every time going from one page to > another i need to fire query into database passing current page index > and retrieving those many records from database according to page > size? Yes you have to go to database to get result for currently selected page. In our examples you would have to run queries to get records with sequence number within result set Case 1) from 1 to 10 Case 2) from 11 to 20 Case 3) from 31 to 40 but due to the fact there are only five records on this page you would get records from 31 to 35. It it clear now? Best regards Milosz |
|
|
| Similar Threads | |
| VirtualItemCount in Gridview is missing Hello there, has the GridView control in ASP.NET a property like the VirtualItemCount of the DataGrid control? I am very appreciated for your help. Kamen |
|
| Adding Dynamic Controls to a DataGrid for use with the built in DataGrid Edit/Update functionality (VS 2003, .NET 1.1) I am trying to add dynamic controls to the cells of an Edit Row in a DataGrid and am having a terrible time. I cannot for the life of me get the values... |
|
| UserControl inside of datagrid - loses its viewstate when datagrid is re-bound on postback I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of the usercontrol from one... |
|
| custom usercontrol inside of datagrid - loses its state/viewstate on re-bind/postback of the datagrid I have a simple usercontrol, a datepicker which contains 3 dropdownlist , it resides inside a datagrid column and i set the selecteddate property of the usercontrol from one... |
|
| Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Filling One DataGrid Based on Selection from Another DataGrid - Both in Separate User Controls Hello, I have an interesting dilemma. I have an ASPX page with two user... |
|
|
All times are GMT. The time now is 02:34 AM. | Privacy Policy
|