Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1019
  • Last Modified:

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.SortDirection);

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
0
Samm1502
Asked:
Samm1502
1 Solution
 
GiftsonDJohnCommented:
Hi,

You can directly set

MyGridView.DataSource=MyDataStore;
MyGridView.Sort="<column name";
MyGridView.SortDirection = SortDirection.Ascending;
MyGridView.DataBind();
0
 
Samm1502Author Commented:
Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now