My table always sorts in ascending order only when I click the header. Is there a way I can use the sort direction property of the sorting method to automatically sort the table? Thanks to the stack overflow excellent programmers. Below is the existing suggested solution, but it seems it was not properly spelt out. i.e like how to call the method from the event handler assigned for the gridview's OnSorting event..
private void GridViewSortDirection(GridView g, GridViewSortEventArgs e, out SortDirection d, out string f)
{
f = e.SortExpression;
d = e.SortDirection;
//Check if GridView control has required Attributes
if (g.Attributes["CurrentSortField"] != null && g.Attributes["CurrentSortDir"] != null)
{
if (f == g.Attributes["CurrentSortField"])
{
d = SortDirection.Descending;
if (g.Attributes["CurrentSortDir"] == "ASC")
{
d = SortDirection.Ascending;
}
}
g.Attributes["CurrentSortField"] = f;
g.Attributes["CurrentSortDir"] = (d == SortDirection.Ascending ? "DESC" : "ASC");
}
}