Question

It is quite common to use the ASPxGridView event OnFocusedRowChanged to filter data from other components on the screen.

The problem is, when the table is sorted, the property FocusedRowIndex is kept by changing the KeyValue and consequently losing the argument filter we use.

How to avoid this problem?

Was it helpful?

Solution

When the ASPxGridView is sorted, a callback runs.

To avoid the problem, just handle the AfterPerformCallback server-side event with the following code:

int rowIndex = (sender as ASPxGridView).FindVisibleIndexByKeyValue(keyValue);
(sender as ASPxGridView).FocusedRowIndex = (rowIndex == ASPxGridView.InvalidRowIndex) ? -1 : rowIndex;

I'll explain: keep the value of KeyValue used to filter the data of the other components on the screen in Session or in an ASPxHiddenField.

If the value of keyValue is not found, we set the FocusedRowIndex to -1 (which unfocus the row), otherwise we always keep the same keyValue focused.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top