We help IT Professionals succeed at work.

gridview control not updating

dhenderson12 asked
I am having trouble updating the database from the gridview edit row.  I am building the list of parameters to send to a stored proc, calling the stored proc, and then re-loading the gridview.  However,  at the point where I am populating the values for the parameters, I am getting the original values, not the new values I have already typed into the text boxes.

here are the two events in play:

protected void gvCallList_RowEditing(object sender, GridViewEditEventArgs e)
    gvCallList.EditIndex = e.NewEditIndex;

protected void gvCallList_RowUpdating(object sender, GridViewUpdateEventArgs e)
    int idx = gvCallList.EditIndex;
    GridViewRow row = gvCallList.Rows[idx];
    string RowId = gvCallList.DataKeys[idx].Value.ToString();

    string PharmacyName = ((TextBox)row.FindControl("txtPharmacyName")).Text;
    string Address1 = ((TextBox)row.FindControl("txtAddress1")).Text;
    string Address2 = ((TextBox)row.FindControl("txtAddress2")).Text;
    string City = ((TextBox)row.FindControl("txtCity")).Text;
    string State = ((TextBox)row.FindControl("txtState")).Text;
    string Zip = ((TextBox)row.FindControl("txtZip")).Text;
    string PhoneNo = ((TextBox)row.FindControl("txtPhoneNo")).Text;
    string FaxNo = ((TextBox)row.FindControl("txtFaxNo")).Text;

      List<ParameterDefinition> inParams = new List<ParameterDefinition>();

      inParams.Add(new ParameterDefinition("RowId", DbType.Int64, Int64.Parse(RowId.ToString())));
      inParams.Add(new ParameterDefinition("PharmacyName", DbType.String, PharmacyName));
      inParams.Add(new ParameterDefinition("Address1", DbType.String, Address1));
      inParams.Add(new ParameterDefinition("Address2", DbType.String, Address2));
      inParams.Add(new ParameterDefinition("City", DbType.String, City));
      inParams.Add(new ParameterDefinition("State", DbType.String, State));
      inParams.Add(new ParameterDefinition("Zip", DbType.String, Zip));
      inParams.Add(new ParameterDefinition("PhoneNo", DbType.String, PhoneNo));
      inParams.Add(new ParameterDefinition("FaxNo", DbType.String, FaxNo));

      DataAccess.ExecuteProcedure("DataConnection", "CallList_Update", inParams);
      gvCallList.EditIndex = -1;

    catch (Exception ex)

Watch Question

Developer User Interface
You should be using the e.NewValues property.


thanks for the response, but I just found the issue:  it was a post-back issue.  I was loading the database on every page load, not looking for post-back.  I works now just by calling the load on if (! IsPostBack).  you get cheap points for this one.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.