Hi everyone,

Greetings for the day.
In my application I am sorting the gridview and also have Edit in that gridview, sorting works fine but when i click Edit, it puts the gridview in the original sorted order. when i click Edit - it lets me edit the row but it changes the order and show me the original record on that row in the edit mode.
where is the problem in my code i m not able to figure it out. looking for help. i need to finish it urgently.
below is my code:
protected void GridDispatchshow_RowEditing(object sender, GridViewEditEventArgs e)
{
GridDispatchshow.EditIndex = e.NewEditIndex;
Label lblpblm = (Label)GridDispatchshow.Rows[e.NewEditIndex].Cells[10].FindControl("lblproblemfaced");
Label lbladd = (Label)GridDispatchshow.Rows[e.NewEditIndex].Cells[11].FindControl("lblproblemfaced");
fillgridview();
DropDownList ddlpblm = (DropDownList)GridDispatchshow.Rows[e.NewEditIndex].Cells[10].FindControl("ddlpblmfaced");
ddlpblm.SelectedValue = lblpblm.Text;
DropDownList ddladd = (DropDownList)GridDispatchshow.Rows[e.NewEditIndex].Cells[11].FindControl("ddladdressinvalid");
ddladd.SelectedValue = lbladd.Text;

if (ViewState["SortOrder"] != null)
{
DataTable edt = (DataTable)ViewState["SortOrder"];
GridDispatchshow.DataSource = edt;
GridDispatchshow.DataBind();
}
else
{
fillgridview();
}
}

protected void GridDispatchshow_Onsorting(object sender, GridViewSortEventArgs e)
{
string sorting = string.Empty;
if (GridViewSortDirection == SortDirection.Ascending)
{
GridViewSortDirection = SortDirection.Descending;
sorting = "Desc";
}
else
{
GridViewSortDirection = SortDirection.Ascending;
sorting = "Asc";
}
DataTable dt = (DataTable)Cache["dt"];
DataView sortedview = new DataView(dt);
sortedview.Sort = e.SortExpression + " " + sorting;
GridDispatchshow.DataSource = sortedview;
GridDispatchshow.DataBind();
ViewState["SortOrder"] = ((DataView)GridDispatchshow.DataSource).ToTable();

}
public SortDirection GridViewSortDirection
{
get
{
if (ViewState["sortDirection"] == null)
ViewState["sortDirection"] = SortDirection.Ascending;
return (SortDirection)ViewState["sortDirection"];
}
set { ViewState["sortDirection"] = value; }
}