protected void gvBrandDetails_RowUpdating(object sender, GridViewUpdateEventArgs e) { Label lblBrandID = (Label)gvBrandDetails.Rows[e.RowIndex].FindControl("lblBrandID"); TextBox txtEditBrandName = (TextBox)gvBrandDetails.Rows[e.RowIndex].FindControl("txtEditBrandName"); TextBox txtEditDescription = (TextBox)gvBrandDetails.Rows[e.RowIndex].FindControl("txtEditDescription"); ListBox lstCategory = (ListBox)gvBrandDetails.Rows[e.RowIndex].FindControl("ddlEditCategory"); if (txtEditBrandName.Text != ("") && txtEditDescription.Text != ("") && lstCategory.Text != ("")) { Domain.Brand existing = brandRepo.GetById(Convert.ToInt32(lblBrandID.Text)); if (existing != null) { existing.BrandName = txtEditBrandName.Text; existing.BrandDescription = txtEditDescription.Text; existing.LastUpdatedBy = "admin"; existing.TenantId = tenantId; existing.LastUpdationTime = DateTime.Now; } existing.CategoryBrandMappings = new List <CategoryBrandMapping>(); int[] existingIds = existing.CategoryBrandMappings.Select(c => c.CategoryBrandMappingId).ToArray(); foreach (var id in existingIds) { mappingRepo.Delete(id); } foreach (var index in lstCategory.GetSelectedIndices()) { existing.CategoryBrandMappings.Add(new CategoryBrandMapping() { Brand = existing, CategoryId = Convert.ToInt32(lstCategory.Items[index].Value), TenantId = tenantId }); } brandRepo.Edit(existing); brandRepo.Save(); gvBrandDetails.EditIndex = -1; BindData(); ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Brand Sucessfully Updated');", true); } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Null Filled Not allowed');", true); } //conn.Open(); //string cmdstr = "update EmployeeDetails set name=@name,designation=@designation,city=@city,country=@country where empid=@empid"; //SqlCommand cmd = new SqlCommand(cmdstr, conn); //cmd.Parameters.AddWithValue("@empid", lblEditEmpID.Text); //cmd.Parameters.AddWithValue("@name", txtEditName.Text); //cmd.Parameters.AddWithValue("@designation", txtEditDesignation.Text); //cmd.Parameters.AddWithValue("@city", txtEditCity.Text); //cmd.Parameters.AddWithValue("@country", txtEditCountry.Text); //cmd.ExecuteNonQuery(); //conn.Close(); //gvBrandDetails.EditIndex = -1; //BindData(); }
protected void gvBrandDetails_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName.Equals("ADD")) { TextBox txtAddBrandName = (TextBox)gvBrandDetails.FooterRow.FindControl("txtAddBrandName"); TextBox txtAddDescription = (TextBox)gvBrandDetails.FooterRow.FindControl("txtAddDescription"); ListBox lstCategory = (ListBox)gvBrandDetails.FooterRow.FindControl("lstCategory"); if (txtAddBrandName.Text != ("") && txtAddDescription.Text != ("") && lstCategory.Text != ("")) { Domain.Brand brand = new Domain.Brand() { BrandDescription = txtAddDescription.Text, BrandName = txtAddBrandName.Text, CreationTime = DateTime.Now, LastUpdationTime = DateTime.Now, CreatedBy = "admin", LastUpdatedBy = "admin", TenantId = tenantId, }; brand.CategoryBrandMappings = new List <CategoryBrandMapping>(); foreach (var index in lstCategory.GetSelectedIndices()) { brand.CategoryBrandMappings.Add(new CategoryBrandMapping() { Brand = brand, CategoryId = Convert.ToInt32(lstCategory.Items[index].Value), TenantId = tenantId }); } brandRepo.Add(brand); brandRepo.Save(); BindData(); ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Brand Sucessfully Inserted');", true); BindData(); } else { ScriptManager.RegisterStartupScript(this, GetType(), "showalert", "alert('Null Filled Not allowed');", true); } } //conn.Open(); //string cmdstr = "insert into EmployeeDetails(empid,name,designation,city,country) values(@empid,@name,@designation,@city,@country)"; //SqlCommand cmd = new SqlCommand(cmdstr, conn); //cmd.Parameters.AddWithValue("@empid", txtAddEmpID.Text); //cmd.Parameters.AddWithValue("@name", txtAddName.Text); //cmd.Parameters.AddWithValue("@designation", txtAddDesignation.Text); //cmd.Parameters.AddWithValue("@city", txtAddCity.Text); //cmd.Parameters.AddWithValue("@country", txtAddCountry.Text); //cmd.ExecuteNonQuery(); //conn.Close(); //BindData(); }