views:

90

answers:

2

Hi, I want to sort my gridview binded to an object datasource fetching business objects. I have already implemented custom paging & now want to implement sorting. Just read this article but there is lot of concatenation going on there with the SQL Query. Any other elegant solution guys ?

http://aspnet.4guysfromrolla.com/articles/032206-1.aspx#

+1  A: 

How about sorting using .DefaultView? Following is upon grd_Sorting event.

DataView dv = dt.DefaultView;//Your datatable, dt.
dv.RowFilter = "";//Set row filter to none.
if ((strSortBy != null) && (strSortAscending != null))
    dv.Sort = strSortBy/*Column name*/ + " " + strSortAscending /*ASC, for instance.*/;

grd.DataSource = dv;
grd.DataBind();
KMan
Hi my object data source returns List<T> with custom business objects. Would this solution work with that ? Also I am using custom paged data (like 10 objects per gridview page)
Popo
@Popo: In that case, I would implement an IComparable for my custom object. See http://www.switchonthecode.com/tutorials/csharp-snippet-tutorial-custom-list-sorting
KMan
Thanks for the reply. But, that would mean only sorting 10 records and not all records from the database (the query only fetches 10 rows per gridview page so sorting them isn't what Ia m looking for). I think its only possible on database level.
Popo
A: 

Solved it at query level with a dynamic where clause.

Popo