protected void grdSurveys_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { string dateStr = (string)e.NewValues["survey_date"]; // validate the date if (!Validatesurvey_date(dateStr)) { lblMessage.Text = "Survey date is not in the correct format. Example: 4/13/2001"; lblMessage.Visible = true; } else { Survey lSurvey = new Survey(); this.grdSurveys.EditIndex = e.RowIndex; mmGridView gv = (mmGridView)sender; object rowPrimaryKey = gv.DataKeys[e.RowIndex].Value; lSurvey.LoadRow(rowPrimaryKey); // assign all the values to the appropriate DataTable Row DataRow editDataRow = lSurvey.DataRow; editDataRow["job_id"] = e.NewValues["job_id"]; if (dateStr != null) { if (dateStr.Trim() != String.Empty) editDataRow["survey_date"] = DateTime.Parse(dateStr); else editDataRow["survey_date"] = DBNull.Value; } else editDataRow["survey_date"] = DBNull.Value; editDataRow["lot_id"] = e.NewValues["lot_id"]; editDataRow["address_line1"] = e.NewValues["address_line1"]; editDataRow["address_line2"] = e.NewValues["address_line2"]; editDataRow["city"] = e.NewValues["city"]; editDataRow["state"] = e.NewValues["state"]; editDataRow["zip"] = e.NewValues["zip"]; // attempt to save the dataset mmSaveDataResult result = lSurvey.SaveEntity(); // if there are errors display them above the datagrid if (result == mmSaveDataResult.RulesBroken) { lblMessage.Text = lSurvey.Rules.GetAllBrokenRules(); lblMessage.Visible = true; } else { lblMessage.Text = String.Empty; lblMessage.Visible = false; } } this.grdSurveys.EditIndex = -1; e.Cancel = true; } catch (Exception ex) { e.Cancel = true; lblMessage.Text = ex.Message; lblMessage.Visible = true; } }