ASP.net: How to make list of object sortable when bind to control such as gridview

asp.net

I got a class let's call it Blah. I use ObjectDataSource to get the data from the database and the value is bind it to Blah's property for example, Column Foo is Blah.Foo in my class. I can bind ObjectDataSource with a list of Blah to a gridview but i can't make it sortable since the datasource is not datatable. Does anyone have link or tutorial on how to make object to be sortable for control like gridview.

thank

Jack

Best Answer

First you could use the AllowSorting property of the gridview with SortExpression on your fields. Here is a tutorial

Second, you could made a generic list of Blah and then call .Sort()

List<Blah> test = new List<Blah>;
test.AddRange(ObjectDataSource);
test.Sort();

msdn information

Third you could sort the gridview directly from an expression like

CustomersGridView.Sort(expression, direction);

link

Related Topic