I use a gridview on my asp.net page. And write a code for sorting, but the problem is that the sorting is not working. Can you please tell me what i am doing mistake.
Code for bind the gridview
DataSet _ds = _fOrderWrapper.ExecuteDataSet();
ViewState["FOrders"] = _rows;
lblFinalisedCount.Text = _ds.Tables[0].Rows.Count.ToString();
GridOpen.DataSource = _ds.Tables[0];
ViewState["dt"] = _ds.Tables[0];
ViewState["sort"] = "ASC";
GridOpen.DataBind();
UpdatePanel1.Update();
Sorting Event code :
try
{
DataTable dt1 = (DataTable)ViewState["dt"];
if (dt1.Rows.Count > 0)
{
if (Convert.ToString(ViewState["sort"]) == "ASC")
{
dt1.DefaultView.Sort = e.SortExpression +" " + "DESC";
ViewState["sort"] = "Desc";
}
else
{
dt1.DefaultView.Sort = e.SortExpression +" "+ "ASC";
ViewState["sort"] = "ASC";
}
GridOpen.DataSource = dt1;
GridOpen.DataBind();
UpdatePanel1.Update();
}
}
catch (Exception ex)
{
}