How to re-select row in a gridview _after_ sorting?

  • Thread starter Thread starter Bogdan
  • Start date Start date
B

Bogdan

Hi,

I have a gridview with ObjectDataSource attached and page/sort enabled. A
user can select a row on a given page. The app 'remembers' data item linked
to the selected row. The row is rendered as selected only if a user
navigates to the page containing the selected data. A user can navigate to
the selected data item's detail page and then come back to the grid view.
Although the 'coming back' is not a page postback, the corresponding row
will still be selected and a proper page displayed.
This is relatively easy to do - I simply handle the Selected event of the
data source object and based on its table content I calculate current page
index and selected index (i.e. if the selected data happens to be on the
current page).

Unfortunately the above approach does not work when sorting is involved.
The sort occurs after the Selected event so I have no way of determining on
what page the selected data item is.

Is there another way I could accomplish the above? Is there an event fired
_after_ the ObjectDataSource sort operation is performed?

Thanks,
Bogdan
 
Unfortunately the above approach does not work when sorting is
involved. The sort occurs after the Selected event so I have no way of
determining on what page the selected data item is.

You mean "the default methodology does not allow me to selected a sorted
list".

Assume you are also using paging?

If you want a user to select a row, remember the row, and have paging
and sorting, you will have to do some work on the result set yourself.
You will also have to store pointers and create the grid results. It is
not impossible, just work.

As a high level, I would suggest binding a DataView to the Grid. You
then have to figure out what the grid consists of and create the proper
row filter.

Ultimately, this means custom paging and sorting, but there are plenty
of Google hits on both topics. You will also need to keep "state" as far
as selected row goes. This can be stored in ViewState, if you want it
for this page alone.

Hope this helps.

Peace and Grace,

--
Gregory A. Beamer (MVP)

Twitter: @gbworld
Blog: http://gregorybeamer.spaces.live.com

*******************************************
| Think outside the box! |
*******************************************
 
Back
Top