Samm1502
asked on
How to set SortExpression of GridView before calling DataBind()
Hi there
I have a GridView whose columns are created dynamically. I have an ObjectDataSource too but my page allows records to either be cached or to be requested from the database with each post back therefore I also set the dataSource of my grid dynamically to either my cached DataTable or to the Select method results from my DataSource.
Therefore when I want to sort by one of my dynamically created columns I provide a gridView_Sorting method and in there I chek whether i am caching or not if I am I just sort my cached DataTable as follows:
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql( e.SortDire ction);
in my GridView_Sorting method.
How ever if I am not caching then I bind my GridView to my ObjectDataStore and then call DataBind on the GridView however now my GridView.SortEXpression is not set. I know my column sort expression because it's in e.SortExpression but this doesn't get passed to my ObjectDataStore's select method so how do I pass it.
My code is:
MyGridView.DataSource = MyDataStore;
MyGridView.DataBind();
so how to ste MyGridView.SortExpression to e.SortExpression??
Many thanks
Sam
I have a GridView whose columns are created dynamically. I have an ObjectDataSource too but my page allows records to either be cached or to be requested from the database with each post back therefore I also set the dataSource of my grid dynamically to either my cached DataTable or to the Select method results from my DataSource.
Therefore when I want to sort by one of my dynamically created columns I provide a gridView_Sorting method and in there I chek whether i am caching or not if I am I just sort my cached DataTable as follows:
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(
in my GridView_Sorting method.
How ever if I am not caching then I bind my GridView to my ObjectDataStore and then call DataBind on the GridView however now my GridView.SortEXpression is not set. I know my column sort expression because it's in e.SortExpression but this doesn't get passed to my ObjectDataStore's select method so how do I pass it.
My code is:
MyGridView.DataSource = MyDataStore;
MyGridView.DataBind();
so how to ste MyGridView.SortExpression to e.SortExpression??
Many thanks
Sam
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER