private void PopulateBrand() { try { List<Brand> lstBrand = new BrandBLL().GetBrand(); cmbBrand.DataSource = lstBrand; cmbBrand.DataValueField = "BrandID"; cmbBrand.DataTextField = "BrandName"; cmbBrand.DataBind(); cmbBrand.Items.Insert(0, new ListItem("--Select--")); cmbBrand.SelectedIndex = 0; } catch (Exception ex) { throw ex; } }
protected void grvBrand_RowUpdating(object sender, GridViewUpdateEventArgs e) { try { int BrandID = 0; string BrandName = string.Empty; TextBox txtControl; txtControl = ((TextBox)grvBrand.Rows[e.RowIndex].FindControl("txtBrandIDE")); if (txtControl.Text != null) { BrandID = Convert.ToInt32(txtControl.Text.Trim()); } txtControl = ((TextBox)grvBrand.Rows[e.RowIndex].FindControl("txtBrandE")); if (txtControl != null) { BrandName = txtControl.Text.Trim(); } int mintReturn = new BLL.Component.BrandBLL().AddEditBrand(BrandID, BrandName); if (mintReturn == -1) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Brand with same name already exists.');", true); } } catch (Exception ex) { } //ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Updated successfully');", true); grvBrand.EditIndex = -1; BindBrand(); }
protected void grvBrand_RowCommand(object sender, GridViewCommandEventArgs e) { try { int BrandID = 0; string BrandName = string.Empty; if (e.CommandName.Equals("Add")) { int retVal = 0; TextBox txtControl; txtControl = ((TextBox)grvBrand.FooterRow.FindControl("txtBrand")); if (txtControl.Text != null) { BrandName = txtControl.Text.Trim(); } retVal = new BLL.Component.BrandBLL().AddEditBrand(-1, BrandName); if (retVal == -1) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Brand with same name already exists');", true); } BindBrand(); } if (e.CommandName.Equals("AddEmpty")) { int retVal = 0; TextBox txtControl; GridViewRow emptyRow = grvBrand.Controls[0].Controls[0] as GridViewRow; txtControl = (TextBox)emptyRow.FindControl("txtBrand1"); if (txtControl.Text != null) { BrandName = txtControl.Text.Trim(); } retVal = new BLL.Component.BrandBLL().AddEditBrand(-1, BrandName); if (retVal == -1) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Brand with same name already exists');", true); } BindBrand(); } } catch (Exception ex) { } }
private void BindBrand() { List<Brand> lstBrand = new BrandBLL().GetBrand(); grvBrand.DataSource = lstBrand; grvBrand.DataBind(); }
protected void grvBrand_RowDeleting(object sender, GridViewDeleteEventArgs e) { int BrandID = Convert.ToInt32(grvBrand.DataKeys[e.RowIndex].Values[0].ToString()); int mintReturn = new BLL.Component.BrandBLL().DeleteBrand(BrandID); if (mintReturn == -1) { ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "alert('Cannot delete. Brand is associated to a Product.');", true); } else { BindBrand(); PopulateBrand(); } ScriptManager.RegisterStartupScript(this, this.GetType(), "alert", "ShowModalDiv('ModalWindow4','dvInnerWindow3',0);", true); }