I have problem on Gridview column sorting.I want to sort each column when click to the column head.I implemented the 'GridView1_Sorting methond by using viewstate and in this way below.
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
//ViewState["sortDirection"] = e.SortExpression == (string)ViewState["sortExpression"] ? ((string)ViewState["sortDirection"] == "ASC" ? "DESC" : "ASC") : "ASC";
//ViewState["sortExpression"] = e.SortExpression;
//GridView1.DataBind();
if (ViewState["sortdirection"] == null)
{
ViewState["sortdirection"] = "ASC";
}
else
{
if (ViewState["sortdirection"].ToString() == "ASC")
{
ViewState["sortdirection"] = "DESC";
}
else
{
ViewState["sortdirection"] = "ASC";
}
}
//Response.Write(ViewState["sortdirection"]);
GridView1.DataBind();
}
protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
{
GridView1.PageIndex = e.NewPageIndex;
GridView1.DataBind();
}
The GridView looks like
<asp:GridView ID="GridView1" runat="server" AllowPaging="True"
AutoGenerateColumns="False" DataSourceID="SqlDataSource1" OnPageIndexChanging="GridView1_PageIndexChanging"
Width="1214px" AllowSorting="True" OnSorting="GridView1_Sorting" PageSize="15">
<FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
<RowStyle BackColor="#DEDFDE" ForeColor="Black" />
It doesn't sort the column.What is the wrong at the "GridView1_Sorting" method.I tried many ways,didn't get sorted.
Any help would be great.
|