This is a migrated thread and some comments may be shown as answers.

[Solved] disable viewstate messes events order up

2 Answers 113 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mink
Top achievements
Rank 1
Mink asked on 02 Nov 2009, 11:35 AM
Hi,

We're having a problem with sorting when we turn the viewstate off for the RadgGrid.
When the viewstate is on (default) first the SortCommand event is fired when a user clicks on a column header to sort, giving us the possibility to alter the query that is going to be used in the NeedDataSource event to set the DataSource of the grid such that the newly requested sorting is applied. Then the NeedDataSource event fires (which uses the query that has been altered in de SortCommand event handler so that the requested sorting is applied).
However, when we turn viewstate off first the NeedDataSource event is handled, using a query that applies the sorting as it was when a user clicked a column header to change the sorting because the query has not yet been altered by the SortCommand event handler, and then the SortCommand event fires altering the query such that is applies the requested sorting but then it's to late, the query has already been used to set the grid's DataSource.

Of coarse it is possible to alter the query in the SortCommand event handler and reset the grid's DataSource, but that way the database is accessed twice of which the first is quite unnecessary.

Does anyone have an idea how to solve this problem?

Regards,

Mink

2 Answers, 1 is accepted

Sort by
0
Accepted
Veli
Telerik team
answered on 05 Nov 2009, 07:39 AM
Hi Mink,

The very idea of the ViewState is that RadGrid does not need to rebind on every postback, as its items are recreated from the ViewState if no changes to the grid structure is made. When you disable the ViewState, RadGrid needs to rebind on every postback, because there is no way it can restore its previous state. Hence, with disabled ViewState NeedDataSource is fired first, so that RadGrid rebinds and recreates its structure. You will need to rebind your grid for a second time after sort command.

All the best,
Veli
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Mink
Top achievements
Rank 1
answered on 05 Nov 2009, 07:57 AM
Hi Veli,

I figured as much.
It is a bit of a waste to go through executing a query twice, but I am sure you are aware of that.
So we'll just have to make do.

Thanks for your reply.
Regards,

Mink
Tags
Grid
Asked by
Mink
Top achievements
Rank 1
Answers by
Veli
Telerik team
Mink
Top achievements
Rank 1
Share this question
or