protected void grdCity_RowUpdating(object sender, GridViewUpdateEventArgs e) { if (IsValid) { GridViewRow row = grdCity.Rows[e.RowIndex]; HiddenField hdnStateId = (HiddenField)row.FindControl("hdnStateId"); TextBox txtState = (TextBox)row.FindControl("txtState"); TextBox txtCityName = (TextBox)row.FindControl("txtCityName"); if (string.IsNullOrWhiteSpace(txtCityName.Text)) { ctlAdminMaster.ErrorMessage = "City Name Can't be Empty"; txtCityName.Focus(); } else { int cityId = Int32.Parse(grdCity.DataKeys[e.RowIndex].Value.ToString()); string CityName = txtCityName.Text; string StateName = txtState.Text; City _city = new City() { CityId = cityId, Name = CityName, StateInfo = new State() { StateId = long.Parse(hdnStateId.Value), Name = StateName } }; try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); if (cityManger.UpdateCity(_city)) { ctlAdminMaster.ErrorMessage = "City Updated Successfully"; } else { ctlAdminMaster.ErrorMessage = "City already exists"; } grdCity.EditIndex = -1; BindData(); } catch (CityManagerException ex) { ctlAdminMaster.ErrorMessage = ex.Message; } } } }
public ActionResult Edit(CityViewModel city) { city.Created_Date = Convert.ToDateTime(Session["CreateDate"]); city.Updated_Date = System.DateTime.Now; bool status = _cityManager.UpdateCity(city); Session["CreateDate"] = null; if (status == false) { return(View(city)); } return(RedirectToAction("Index")); }
protected void grdCity_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = grdCity.Rows[e.RowIndex]; TextBox txtState = (TextBox)row.FindControl("txtState"); TextBox txtCityName = (TextBox)row.FindControl("txtCityName"); if (txtCityName.Text.Length == 0) { lblError.Text = "City Name Can't be Empty"; txtCityName.Focus(); } else { int cityId = Int32.Parse(grdCity.DataKeys[e.RowIndex].Value.ToString()); string CityName = txtCityName.Text; string StateName = txtState.Text; City _city = new City() { CityId = cityId, Name = CityName, StateInfo = new State() { Name = StateName } }; try { ICityManager cityManger = (ICityManager)BusinessObjectManager.GetCityManager(); if (cityManger.UpdateCity(_city)) { lblError.Text = "City Updated Successfully"; } else { lblError.Text = "City already exists"; } grdCity.EditIndex = -1; BindData(); } catch (CityManagerException ex) { throw ex; } } }