protected void lvCountry_ItemCommand(object sender, ListViewCommandEventArgs e) { lblError.Text = string.Empty; lblError.Visible = false; lblSave.Text = string.Empty; lblSave.Visible = false; lblMessage.Visible = false; lblMessage.Text = string.Empty; if (e.CommandName.Equals("DoEdit")) { divEntry.Visible = true; pnlList.Enabled = false; btnSave.Enabled = true; CountryMaster country = CountryMasterManager.GetByCountryId(Convert.ToInt32(e.CommandArgument)); hdId.Value = country.CountryID.ToString(); txtCountryName.Text = country.CountryName; } else if (e.CommandName.Equals("DoDelete")) { try { pnlList.Enabled = true; //pnlEdit.Enabled = false; CountryMaster country = CountryMasterManager.GetByCountryId(Convert.ToInt32(e.CommandArgument)); //country.Status = false; //CountryMasterManager.Save(country); CountryMasterManager.Delete(country); DoBind(); lblSave.Text = "Record Deleted Sucessfully."; lblSave.Visible = true; } catch (Exception ex) { lblError.Text = "Record Not Deleted."; lblError.Visible = true; } } }
protected void btnSave_Click(object sender, ImageClickEventArgs e) { lblError.Text = string.Empty; lblError.Visible = false; lblSave.Text = string.Empty; lblSave.Visible = false; lblMessage.Visible = false; lblMessage.Text = string.Empty; try { //CountryMaster country = CountryMasterManager.GetByCountryId(Convert.ToInt32(hdId.Value)); //country.CountryName = txtCountryName.Text.Trim(); //country.Status = ddlStatus.SelectedValue == "1" ? true : false; //CountryMasterManager.Save(country); //btnCancel_Click(null, null); //lblSave.Text = "Record Saved Sucessfully."; //lblSave.Visible = true; bool isnew = false; CountryMaster country = new CountryMaster(); if (hdId.Value == "0") { isnew = true; } else { country = CountryMasterManager.GetByCountryId(Convert.ToInt32(hdId.Value)); } bool Exists = CountryMasterManager.IsCountryExists(txtCountryName.Text.Trim()); if (isnew) { if (Exists) { lblMessage.Text = "Country Name Exists !!!"; lblMessage.Visible = true; txtCountryName.Focus(); return; } } else { if (country.CountryName != txtCountryName.Text.Trim()) { if (Exists) { lblMessage.Text = "Country Name Exists !!!"; lblMessage.Visible = true; txtCountryName.Focus(); return; } } } country.CountryName = txtCountryName.Text.Trim(); CountryMasterManager.Save(country); btnCancel_Click(null, null); lblSave.Text = "Record Saved Sucessfully."; lblSave.Visible = true; } catch (Exception ex) { lblError.Text = "Record Not Saved."; lblError.Visible = true; } }