Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GridView RowUpdating can't get the new values

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();
}
like image 465
Firze Avatar asked Nov 20 '12 17:11

Firze


2 Answers

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

like image 128
Tleck Aipov Avatar answered Sep 19 '22 00:09

Tleck Aipov


just set Enableviewstate property to false of gridview you can get new value.

<asp:GridView runat="server" EnableViewState="False" ID="GridView6"  AutoGenerateColumns="false" Width="100%"
                EmptyDataText="No Record Found" AllowPaging="false" PageSize="10" OnPageIndexChanging="ChangePage"
                OnRowCommand="RowCommand" OnRowDataBound="GridView6_RowDataBound" >
like image 34
Vipin G Avatar answered Sep 21 '22 00:09

Vipin G