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();
}
}
Lakshmanan Sethu SankaranarayanPosted May 24, 2014, 10:12 AM
Refer this as well
http://msdn.microsoft.com/en-us/library/aa479347.aspx
Anupam SinghPosted May 24, 2014, 8:29 AM
seems you are not binding data on page index change . try this:
or refer this thread
hope it helps.
vijayPosted May 24, 2014, 8:29 AM
Refer the below link for sorting in gridview
http://vdsite.com/Articles/29/How-to-applysorting-in-gridview-in-asp.net