views:

99

answers:

2

Hi All,

I am using C#,ASP.NET

I have a Gridview for which I have provided Sorting, Edit functionality. I am not able to perform EDIT when I perform Sorting. After sorting edit is set on some other row. I think there is some problem with the index it is taking..

Can any one help me how to fix this..

Regards sbmarya

A: 

Please Paste your current code. Thanks.

pjb
protected void gvUsers_RowEditing(object sender, GridViewEditEventArgs e) { gvUsers.EditIndex = e.NewEditIndex; Class2 obj2 = new Class2(); gvUsers.DataSource = obj2.getUsers(); gvUsers.DataBind(); obj2 = null; }
msbyuva
public static Boolean sortDirection; protected void SortMe(object sender, GridViewSortEventArgs e) { Class2 c2 = new Class2(); if (sortDirection) { gvUsers.DataSource = c2.getUsersSortFirstNameDESC(); gvUsers.DataBind(); sortDirection = false; } else { gvUsers.DataSource = c2.getUsersSortFirstNameASC(); gvUsers.DataBind(); sortDirection = true; } }
msbyuva
A: 

I think the issue is that the sorting is using a different call/datasouce than the editing. So in the RowEditing event I am getting an index relative to the sort order (either ASC() or DESC()). But then I am binding using getUsers() which is returning the data in a different order.

What I did is I stored some kind of a flag(Value) in ViewState to indicate what sort order I am in and made use of that when I am binding in the Editing event, so that I can call the right method to return the same datasource.

Regards, sbmarya

msbyuva