views:

16

answers:

1

hi there

i have a gridview populated by a Web Service search function. some of the columns in the grid are templatefields, because the values coming back from the search (in a datatable) are ids - i then use these ids to lookup the values when the rowdatabound event is triggered and populate a label or some such. this means that my sorting function for these id/lookup columns sorts by the ids rather than the textual value that i have looked up and actually populated the grid with (although i do put the ids in the grids datakeys).

what i want to do is top be able to sort by the looked up textual value rather than the codes for these particular columns. what i was going to do to get around this was to when the datatable comes back from the search, adding more columns the textual values and doing all the looking up then, thus being able to sort directly from the manually added columns.

is there another way to do this? as that approach seems like a bit of a bodge. although i guess it does remove having to do the looking up in the rowdatabound event....

my sorting function works by sticking the datatable in the session and on each bind grabbing the sort column and binding the gridview to a DataView with the sort attribute set to the column - and the direction.

thanks

nat

A: 

I dont understand why your datatable is stored in session, how many users do you have? Normally you should rebind your grid to the datasource on every particular event(sorting,paging,editing,...) but not on every postback(gridview is stored in viewstate).

Isnt it possible to get the textual values by sql-joins directly from database? Then you dont need your lookup in rowdatabound and you can set the SortExpression to that column.

Tim Schmelter
hi i stuck the table in the session primarily as the search requires the ability of being bookmarked, and seemed the best way to do that was to redirect with the new QS vars putting the data in the session to be recalled by the new page. cant use viewstate as the page has not been posted. also as i am using the same data on another page that the user almost always clicks through to from this page, and didnt want to have to run the search again..and no i cant do joins and things as this IS the web service and that IS how its going to be unfortunately :(
nat