开发者

Gridview Edit not working after Sorting ASP.NET

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开发者_JAVA技巧..

Regards sbmarya


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


I faced this problem as well. This is how I fixed it. (In my example the gridview is sorted on a column called submit date).

a. When the underlying dataTable of the gridview is crated and sorted store it in a session variable. The trick is, before storing to a session variable make sure you store the sorted view.

                        dt.DefaultView.Sort = "Submit Date" + " " + "DESC";
                        GridView1.DataSource = dt;
                        GridView1.DataBind();
                        Session["gridViewData"] = dt.DefaultView.ToTable(); //Only storing dt will not have the sorted table stored in session.

b. next, perform all edit/update operation using the dataTable stored in session in the above step. It will always come up in proper sorted order and you will not see the issue of row index changing unexpectedly after update.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜