Tuesday, March 8, 2011

GridView's sortExpression is blank while sorting

I am able to get around the issue. What I noticed was that: if the GridView control's DataSourceID is not declaratively assigned i.e. I was assigning a ObjectDataSource to my GridView control each time I wanted to do a databind. In this case, when Sorting is enabled on the GridView, the sortExpression value in the GridViewSortEventArgs is not correctly populated or it is bank.

Also, for my ObjectDataSource, I had delete the SortParameterName="sortExpression" property and explicitly declare the "sortExpression" as a select parameter. Then in the GridView_Sorting event, I have to get the sortExpression value from the GridViewEventArgs and assign it to the ObjectDataSource's "sortExpression" select parameter and then do a DataBind.
Hope I made sense you all. Atleast I can move on from here.

No comments:

Post a Comment