How to sort WebGrid by displayed text instead of underlying data?

6 replies. Last post: January 11, 2013 5:24 AM by Bernard Xiang
Tags :
  • New Discussion
  • New Question
  • New Product Feedback
Eric Member

See this thread for code example:

http://www.intersoftpt.com/Community/WebGrid/WebGrid-How-to-access-Session-object-in-InitializeRow-event-handler/

There's a sorting problem. When sorting by this Name field, it will get sorted by the value in the DataTable from InitializeDataSource, field List_Name. But in InitializeRow I set the ListName.Text (e.Row.Cells.GetNamedItem("xx").Text) to the value that will be displayed. In the case of this example I prepend just "-DIR-" for folders and "-FIL-" for leaf-nodes. When sorting, it won't get sorted by the displayed text, but by the underlying data field (before updating). For this example, the root-level entry "-FIL-a-" comes before "-DIR-b-", just because "a" comes before "b", but the final text is ignored ("-D.." would come before "-F..").

How can I make sure the list gets sorted by the displayed text? Would I have to implement CustomSort event? How?

All times are GMT -5. The time now is 11:31 PM.
Previous Next