Reputation:
I am currently setting my GridView AllowSorting = true. The sorting works fine, but when I click on the edit button for a specific row after sorting, the wrong row gets returned. It edits the row that was previously in the position of the current row before sorting.
Here is my code in the Sorting event.
string sortExpression = e.SortExpression;
string direction = string.Empty;
if (SortDirection == SortDirection.Ascending)
{
SortDirection = SortDirection.Descending;
direction = " DESC";
}
else
{
SortDirection = SortDirection.Ascending;
direction = " ASC";
}
DataTable table = Session["WebUserDT"] as DataTable;
table.DefaultView.Sort = sortExpression + direction;
grdWebUser.DataSource = table;
grdWebUser.DataBind();
Any idea how to solve this?
Upvotes: 0
Views: 1019
Reputation: 581
You should get dataTabe in an WiewState and in rowEditing function you should set this as gridview datasource and bind the gridview and it will be solved
Upvotes: 0