[Solved] EditMode in ASP.Net GridView pointing to different row

akhter
 
on Oct 26, 2021 06:45 AM
798 Views

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;
    BindGrid(searchono.Text.Trim());
}

 

public void BindGrid(string Order_Ref_No)
{
    con = new SqlConnection("Data Source=server;Integrated Security=SSPI;Initial Catalog=zxz;MultipleActiveResultSets=True;");
    con.Open();
    //  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();
    oda.Fill(ds);
    gv1.DataSource = ds;
    gv1.DataBind();
    con.Close();
}

 

Download FREE API for Word, Excel and PDF in ASP.Net: Download
dharmendr
 
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.