Last night us RDs went to a traditional North African sheesha (looks like a fancy bong) bar to smoke fancy tobacco. We even got Andrew Brust to smoke out of it (apple flavored tobacco)! All done with my sessions, so Goksin and I will go visit historic Carthage.
private
void SortGrid(object source,DataGridSortCommandEventArgs e)
{
//SQL String that will be used
string strSQL = "Select * From Customers";
//the Order By
string strOrderBy = "ASC";
//See what the viewstate has for the sortfield and ASC/DESC
if (e.SortExpression.ToString() == ViewState["sortField"].ToString())
{
//a match, see if ASC or DESC
strOrderBy = ViewState["sortDirection"].ToString();
//now toggle the viewstate for later
switch (strOrderBy)
{
case "ASC":
ViewState["sortDirection"] = "DESC";
break;
case "DESC":
ViewState["sortDirection"] = "ASC";
break;
}
}
else
{
//New Field, so it will be ASC by default, so make DESC
ViewState["sortField"] = e.SortExpression.ToString();
ViewState["sortDirection"] = "DESC";
}
//SQL statement compelted
strSQL = strSQL + " " + " ORDER BY [" + e.SortExpression + "] " + strOrderBy;
//set the grid to the first page before you resort
DataGrid1.CurrentPageIndex = 0;
//call the FillGrid method to rebind the grid w/ new OrderBy
FillGrid(strSQL);
}