views:

297

answers:

1

When GridView implements sorting, does it automatically append string values “ASC” or “DESC” to the value of sortExpression parameter? If so, then based on what criteria does it “decide” when to append “ASC” and when to append “DESC” value?

+1  A: 

Yes, it does. Clicking the same column multiple times in a row toggles the sort between ASC and DESC. See MSDN for more info.

Clicking the link button for a column causes the items in the GridView control to be sorted based on the sort expression. Typically, the sort expression is simply the name of the field displayed in the column, which causes the GridView control to sort with respect to that column. To sort by multiple fields, use a sort expression that contains a comma-separated list of field names. You can determine the sort expression that the GridView control is applying by using the SortExpression property. Clicking a column's link button repeatedly toggles the sort direction between ascending and descending order. To determine the current sort direction, use the SortDirection property.

Scott Ivey
Assuming current sort direction is set to SortDirection.Descending, then only way to change the current sort direction is to handle GridView.Sorting event and manually change the sortExpression string by replacing its substring "DESC" with substring "ASC"?
carewithl
No - if you want to change it from the Sorting event - use the GridViewSortEventArgs to do it (e.SortDirection) - http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewsorteventargs.aspx
Scott Ivey
sorry for not replying sooner, but I didn't notice your reply.Anyways, I really appreciate your help
carewithl