user2140883
user2140883

Reputation:

With this code I can't get update nothing changes

It's a GridView Update there are no syntax problems.

After updating ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt")).Text; it returns same text nothing changes I can't get the text which I typed in update mode in textbox

example : if I have text - someText

in update I typed - newText

at the end It returns - someText

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e) {
    int id = Convert.ToInt32((GridView1.Rows[e.RowIndex].FindControl("Label1ID") as Label).Text);
    PersonData data = (from x in Domain.Instance.PersonDatas
                                         where x.ID == id
                                         select x).First();

    data.Info = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt")).Text;
    data.Info1 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt1")).Text;
    data.Info2 = ((TextBox)GridView1.Rows[e.RowIndex].FindControl("txt2")).Text;

    Domain.Instance.SaveChanges();

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

there is a property :

  <asp:TemplateField HeaderText="Info">
                    <EditItemTemplate>
                        <asp:TextBox ID="txt" runat="server" Text='<%# Eval("Info") %>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <asp:Label ID="LabelInfo" runat="server" Text='<%# Eval("Info") %>'></asp:Label>
                    </ItemTemplate>
  </asp:TemplateField>

Upvotes: 1

Views: 110

Answers (1)

शेखर
शेखर

Reputation: 17614

I think the problem could be in the binding the gridview.
You should not be binding your gridview on page load.
It should be like follows

 if(!IsPostBack)  /// <<<<<<<<<<
 {
    GridView1.DataSource = yourDataSource;
    GridView1.DataBind();
 }

Upvotes: 2

Related Questions