G
Graham
I have created a server control that reads data from an xml file and renders either a datagrid of entries from a database or group of form controls to allow editing of an individual entry from the same database. The Xml defines how the datagrid and edit form looks and what fields each displays.
The edit form display is perfect but I am having some problems with the datagrid list display.
The datagrid has sorting and pagination enabled and functions correctly when used by itself.
But when the datagrid is used with this server control it has problems with storing its data in ViewState.
At this current time I have the server control being rendered and initialized on each page_load. This is fine the first 10 rows of data is displayed along with the 'skip to page number' pager controls of the datagrid.
When I select another page (say page 2) of the datagrid it goes through these steps:
1. page Posts back to the server
2. The Page page_load function is called which calls the server controls render/init function
3. the server controls render/init function calls the datagrids databind function, populating the datagrid with data for the first page (previous page)
4. Any events are then processed, in this case the PageIndexChanged event (because the page number has changed from 1 to 2)
5. the datagrids databind function is then called again to reflect the changes made by the event calls. This gets the second group of data and populates the datagrid with it.
6. the page is then returned to the user with the second page of data showing along with the pager controls reflecting the change.
this is all how it should be, as far as I know. I ran into trouble when trying to go back to the first page of data, and the data wouldn't change and no events fired (I would have thought the PageIndexChanged event would have considering we were attempting to change the current page).
It turns out that on the first databind the datagrids CurrentPageIndex is not reading from ViewState (where the value is stored) properly, or at all so is always setting its initial value to 0 (Page 1). This then causes the PageIndexChanged event to fire properly on all pages that don't have an index of 0. But when we want to go back the first page the initial CurrentPageIndex = 0 then the new value also = 0 so no event is fired.
I hope that made sense...
Has anyone had problems similar to this that they have managed to fix?
Any help is appreciated.
The edit form display is perfect but I am having some problems with the datagrid list display.
The datagrid has sorting and pagination enabled and functions correctly when used by itself.
But when the datagrid is used with this server control it has problems with storing its data in ViewState.
At this current time I have the server control being rendered and initialized on each page_load. This is fine the first 10 rows of data is displayed along with the 'skip to page number' pager controls of the datagrid.
When I select another page (say page 2) of the datagrid it goes through these steps:
1. page Posts back to the server
2. The Page page_load function is called which calls the server controls render/init function
3. the server controls render/init function calls the datagrids databind function, populating the datagrid with data for the first page (previous page)
4. Any events are then processed, in this case the PageIndexChanged event (because the page number has changed from 1 to 2)
5. the datagrids databind function is then called again to reflect the changes made by the event calls. This gets the second group of data and populates the datagrid with it.
6. the page is then returned to the user with the second page of data showing along with the pager controls reflecting the change.
this is all how it should be, as far as I know. I ran into trouble when trying to go back to the first page of data, and the data wouldn't change and no events fired (I would have thought the PageIndexChanged event would have considering we were attempting to change the current page).
It turns out that on the first databind the datagrids CurrentPageIndex is not reading from ViewState (where the value is stored) properly, or at all so is always setting its initial value to 0 (Page 1). This then causes the PageIndexChanged event to fire properly on all pages that don't have an index of 0. But when we want to go back the first page the initial CurrentPageIndex = 0 then the new value also = 0 so no event is fired.
I hope that made sense...
Has anyone had problems similar to this that they have managed to fix?
Any help is appreciated.