Editmode in GridView pointing to different row in ASP.Net

on Oct 26, 2021 06:45 AM

when i am editing row in gridview ,then it take me another line for editing

For example If I am editing IDOD 36387 line, then i click on edit, it take me on IDOD 36389.

protected void gv1_RowEditing(object sender, GridViewEditEventArgs e)
    gv1.EditIndex = e.NewEditIndex;


public void BindGrid(string Order_Ref_No)
    con = new SqlConnection("Data Source=server;Integrated Security=SSPI;Initial Catalog=zxz;MultipleActiveResultSets=True;");
    //  SqlCommand ocmd = new SqlCommand("Spsearchordernogv", con);
    SqlCommand ocmd = new SqlCommand("Order_wiseStatus_Prd_pendGV", con);
    ocmd.CommandType = CommandType.StoredProcedure;
    ocmd.Parameters.AddWithValue("@Order_Ref_No", Order_Ref_No);
    SqlDataAdapter oda = new SqlDataAdapter(ocmd);
    SqlCommandBuilder builder = new SqlCommandBuilder(oda);
    DataSet ds = new DataSet();
    gv1.DataSource = ds;


Download FREE API for Word, Excel and PDF in ASP.Net: Download
on Oct 27, 2021 04:41 AM

Hi akhter,

As your code looks ok. This shouldn't happen at all.

So, I think when Edit clicked, GridView rebinds, but gets records from SQL server in a different order.

Try to add Order By on primary key in the select stored procedure.