How to perform sorting in a grid view i am using this code but it is sorting the data in a single page and when we click on next page through paging the page is going blank and no data will be shown and again we click on paging same data will be reflecting on the first paging.
public SortDirection dir
{
get
{
if (ViewState["dirState"] == null)
{
ViewState["dirState"] = SortDirection.Ascending;
}
return (SortDirection)ViewState["dirState"];
}
set
{
ViewState["dirState"] = value;
}
}
protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
{
BindGrid();
{
string SortDir = string.Empty;
if (dir == SortDirection.Ascending)
{
dir = SortDirection.Descending;
SortDir = "Desc";
}
else
{
dir = SortDirection.Ascending;
SortDir = "Asc";
}
DataView sortedView = new DataView(dt);
sortedView.Sort = e.SortExpression + " " + SortDir;
GridView1.DataSource = sortedView;
GridView1.DataBind();
}
}

vijay172 reputationPosted May 24, 2014, 4:29 AM EDT
Refer the below link for sorting in gridview
http://vdsite.com/Articles/29/How-to-applysorting-in-gridview-in-asp.net
Anupam SinghRank #643 · 3.7K reputationPosted May 24, 2014, 4:29 AM EDT
seems you are not binding data on page index change . try this:
or refer this thread
hope it helps.
Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted May 24, 2014, 6:12 AM EDT
Refer this as well
http://msdn.microsoft.com/en-us/library/aa479347.aspx