protected void CityAddButton_Click(object sender, EventArgs e) { try { if (CityNameTextBox.Text.Trim().Length == 0) { System.Windows.Forms.MessageBox.Show(new System.Windows.Forms.Form { TopMost = true }, "Don't accept Space char in your name"); Focus(); } CPT_CityMaster Citydetails = new CPT_CityMaster(); Citydetails.RegionID = Convert.ToInt32(RegionList.SelectedValue); Citydetails.CountryID = Convert.ToInt32(CountryList.SelectedValue); Citydetails.CityName = CityNameTextBox.Text.Trim(); Citydetails.IsActive = true; CityMasterBL insertCity = new CityMasterBL(); insertCity.Insert(Citydetails); BindGrid(); CleartextBoxes(this); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
private void BindGrid() { List <CPT_CityMaster> lstCity = new List <CPT_CityMaster>(); CityMasterBL clsAccount = new CityMasterBL(); lstCity = clsAccount.getCity(); gvCity.DataSource = lstCity; gvCity.DataBind(); }
protected void delete(object sender, GridViewDeleteEventArgs e) { CPT_CityMaster Citydetails = new CPT_CityMaster(); int id = int.Parse(gvCity.DataKeys[e.RowIndex].Value.ToString()); Citydetails.CityID = id; CityMasterBL deleteCity = new CityMasterBL(); deleteCity.Delete(Citydetails); BindGrid(); }
protected void update(object sender, GridViewUpdateEventArgs e) { try { CPT_CityMaster Citydetails = new CPT_CityMaster(); int id = int.Parse(gvCity.DataKeys[e.RowIndex].Value.ToString()); Citydetails.CityID = id; string CityName = ((TextBox)gvCity.Rows[e.RowIndex].Cells[3].Controls[0]).Text; Citydetails.CityName = CityName; CityMasterBL updateCity = new CityMasterBL(); updateCity.Update(Citydetails); gvCity.EditIndex = -1; BindGrid(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }