0

I want to sort my GridView bound 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?

https://web.archive.org/web/20211020202742/https://aspnet.4guysfromrolla.com/articles/032206-1.aspx#

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

3 Comments

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: In that case, I would implement an IComparable for my custom object. See switchonthecode.com/tutorials/…
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.
0

Solved it at query level with a dynamic where clause.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.