Link to home
Start Free TrialLog in
Avatar of skaleem1
skaleem1Flag for Canada

asked on

e.NewEditIndex value in the GridView1_RowEditing event are reset incorrectly for every page when AllowPaging is set to true

I am programatically adding columns to a gridview from a dataset and binding the gridview utilizing the related datatable. I am also adding the edit and delete buttons programatically as in the code below:

CommandField Edit = new CommandField();
                    Edit.HeaderText = "";
                    Edit.ShowEditButton = true;
                    Edit.EditText = "Edit";
                    Edit.UpdateText = "Save";
                    Edit.CancelText = "Cancel";
                    Edit.ItemStyle.ForeColor = System.Drawing.Color.FromName("#344F3E");
                    this.GridView1.Columns.Add(Edit);

                    CommandField Delete = new CommandField();
                    Delete.HeaderText = "";
                    Delete.ShowDeleteButton = true;
                    Delete.ItemStyle.ForeColor = System.Drawing.Color.FromName("#344F3E");
                    this.GridView1.Columns.Add(Delete);

When the Edit button is clicked, the GridView1_RowEditing event fires where I am redirecting to another page passing few querystring parameters including the row index info as e.NewEditIndex (the logic for editing is done in the redirected page utilizing this row info passed). See the following code:

public void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {
           
            Response.Redirect(string.Format("~/LookupAddEditData.aspx?mode={0}&op={1}&row={2}&source={3}", _pageMode, "edit", e.NewEditIndex, "Released"));
        }

Every thing worked fine when the Gridview1.AllowPaging was set to false. However, when I changed this to true, the e.NewEditIndex counter is reset for every page thus giving me the erroneous row info (for each page it starts with the lowest value again and again). How can I resolve this problem, any ideas, code and thoughts will be very much appreciated.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of skaleem1
skaleem1
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial