Published in: C#
OnSorting="gvName_Sorting" OnPageIndexChanging="gvName_PageIndexChanging" protected void gvName_PageIndexChanging(object sender, GridViewPageEventArgs e) { gvName.PageIndex = e.NewPageIndex; BindEvents(); } protected void gvName_Sorting(object sender, GridViewSortEventArgs e) { GridViewSortExpression = e.SortExpression; SetSortDirection(); BindEvents(); } protected void BindEvents() { dvName.Sort = GridViewSortExpression + " " + GridViewSortDirection; dvName.DataSource = dvEvents; dvName.DataBind(); } private string GridViewSortDirection { get { return ViewState["SortDirection"] as string ?? "DESC"; } set { ViewState["SortDirection"] = value; } } private string GridViewSortExpression { get { return ViewState["SortExpression"] as string ?? "DEFAULT SORT COLUMN"; } set { ViewState["SortExpression"] = value; } } private void SetSortDirection() { GridViewSortDirection = (GridViewSortDirection == "DESC") ? "ASC" : "DESC"; }
You need to login to post a comment.
