GridView RowUpdating can’t get the new values

asp.netgridview

I was just testing if I will get the changed value out of the textbox when updating with no luck. I just cant get the new value. What am I doing wrong? I have tried numerous things. And this is the latest one. How can I get the updated new value to my label? When I click edit on the grid and change the value of the textbox and click update the label will just display the original value of the textbox.

protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
    GridView1.EditIndex = e.NewEditIndex;

    bindgrid();
}

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    GridViewRow row = GridView1.Rows[e.RowIndex];
    Label1.Text = ((TextBox)(GridView1.Rows[GridView1.EditIndex]).Cells[2].Controls[0]).Text;

    GridView1.EditIndex = -1;
    bindgrid();
}

Best Answer

I think when you push update link Gridview is binding again before taking new value. You must use if(!IsPostBack) before GridView.DataBind().

Related Topic