<asp:GridView ID=" gvSorting " SkinID="GridView" EmptyDataText="No Records to Display" runat="server" AutoGenerateColumns="true" Width="100%" OnSorting="gvSorting_Sorting" AllowSorting="True"></asp:GridView>
In .cs Page
When Binding Grid
gvSorting.DataSource = Dt;
gvSorting.DataBind();
Session["_Dt"] = Dt;
ViewState["Sort_Order"] = "ASC";
protected void gvSorting_Sorting(object sender, GridViewSortEventArgs e)
{
if (ViewState["Sort_Order"].ToString() == "ASC")
RebindData(e.SortExpression, "DESC");
else
RebindData(e.SortExpression, "ASC");
}
private void RebindData(string sColimnName, string sSortOrder)
{
DataTable dt = (DataTable)Session["_Dt"];
dt.DefaultView.Sort = sColimnName + " " + sSortOrder;
gvSorting.DataSource = dt;
gvSorting.DataBind();
ViewState["Sort_Order"] = sSortOrder;
}
No comments:
Post a Comment