I have implemented the sort function in my codebehind, it works fine with words but not with numbers... eg
4,693
1,494
23
when i sort this i get
> 1,494
> 23
> 4,693
so this means its just checking the first number....
my code for sort is:
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
if (IsPostBack)
{
DataTable dt = Session["TaskTable"] as DataTable;
if (dt != null)
{
//Sort the data.
dt.DefaultView.Sort = e.SortExpression + " " + GetSortDirection(e.SortExpression);
GridView1.DataSource = Session["TaskTable"];
GridView1.DataBind();
}
}
else
{
Response.Redirect("~/Reports1mod.aspx");
}
}
private string GetSortDirection(string column)
{
// By default, set the sort direction to ascending.
string sortDirection = "ASC";
// Retrieve the last column that was sorted.
string sortExpression = ViewState["SortExpression"] as string;
if (sortExpression != null)
{
// Check if the same column is being sorted.
// Otherwise, the default value can be returned.
if (sortExpression == column)
{
string lastDirection = ViewState["SortDirection"] as string;
if ((lastDirection != null) && (lastDirection == "ASC"))
{
sortDirection = "DESC";
}
}
}
// Save new values in ViewState.
ViewState["SortDirection"] = sortDirection;
ViewState["SortExpression"] = column;
return sortDirection;
}