Hello,
I have a Gridview in my aspx page and I have the following code for Sorting. Though the records are getting sorted for some reason the image is always showing Up arrow.
I don't know what is the problem.
Thanks in advance for your help.
protected void GridView_Sorting(object sender, GridViewSortEventArgs e)
{
try
{
GridView GridViewSender = sender as GridView;
DataTable dataTable = ViewState["dt"] as DataTable;
if (dataTable != null)
{
DataView dataView = new DataView(dataTable);
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e);
GridViewSender.DataSource = dataView;
GridViewSender.DataBind();
}
}
catch (Exception ex)
{
}
}
private string ConvertSortDirectionToSql(GridViewSortEventArgs e)
{
string newSortDirection = String.Empty;
if (ViewState["sortColumn"] == null)
{
ViewState["sortColumn"] = "";
}
if (ViewState["sortColumn"].ToString() == e.SortExpression.ToString())
{
if ("ASC" == ViewState["sortDirection"].ToString())
{
ViewState["sortDirection"] = "DESC";
newSortDirection = "DESC";
}
else
{
ViewState["sortDirection"] = "ASC";
newSortDirection = "ASC";
}
}
else
{
ViewState["sortColumn"] = e.SortExpression.ToString();
ViewState["sortDirection"] = "ASC";
newSortDirection = "ASC";
}
return newSortDirection;
}
private string ConvertSortDirectionToSql(GridViewSortEventArgs e)
{
string newSortDirection = String.Empty;
if (ViewState["sortColumn"] == null)
{
ViewState["sortColumn"] = "";
}
if (ViewState["sortColumn"].ToString() == e.SortExpression.ToString())
{
if ("ASC" == ViewState["sortDirection"].ToString())
{
ViewState["sortDirection"] = "DESC";
newSortDirection = "DESC";
}
else
{
ViewState["sortDirection"] = "ASC";
newSortDirection = "ASC";
}
}
else
{
ViewState["sortColumn"] = e.SortExpression.ToString();
ViewState["sortDirection"] = "ASC";
newSortDirection = "ASC";
}
return newSortDirection;
}