/// <summary> /// Fires when Update button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void UpdateRecord(object sender, GridViewUpdateEventArgs e) { int personID = Int32.Parse(GridView1.DataKeys[e.RowIndex].Value.ToString()); int intResult = 0; GridViewRow row = GridView1.Rows[e.RowIndex]; TextBox tFN = (TextBox) row.FindControl("txtFName"); TextBox tLN = (TextBox)row.FindControl("txtLName"); TextBox tAge = (TextBox)row.FindControl("txtAge"); // instantiate BAL PersonBAL pBAL = new PersonBAL(); Person person = new Person(); try { person.PersonID = personID; person.FirstName = tFN.Text; person.LastName = tLN.Text; person.Age = Int32.Parse(tAge.Text); intResult = pBAL.Update(person); if (intResult > 0) lblMessage.Text = "Record Updated Successfully."; else lblMessage.Text = "Record couldn't updated"; } catch (Exception ee) { lblMessage.Text = ee.Message.ToString(); } finally { person = null; pBAL = null; } GridView1.EditIndex = -1; // Refresh the list BindGrid(); }