/// <summary> /// This method Binds the gridview /// </summary> private void BindGridView() { lblMessage.Text = ""; IAdminBLL objBLL = AdminBLLFactory.CreateAdminBLLObject(); gvItemList.DataSource = objBLL.GetItemDetails(Convert.ToInt32(ddlCategory.SelectedValue)); gvItemList.DataBind(); }
/// <summary> /// This method deleted the Item details from the gridview list /// </summary> protected void btnDelete_Click(object sender, EventArgs e) { bool isItemSelected = false; bool isdeleted = false; IAdminBLL objBLL = AdminBLLFactory.CreateAdminBLLObject(); try { List <int> selectedCategoryList = new List <int>(); lblMessage.Text = ""; //loop through the grid to find the selected item for (int i = 0; i < gvItemList.Rows.Count; i++) { GridViewRow gvItem = gvItemList.Rows[i]; isItemSelected = ((CheckBox)gvItem.FindControl("chkItem")).Checked; if (isItemSelected) { selectedCategoryList.Add(Convert.ToInt32(gvItemList.Rows[i].Cells[1].Text)); } if (selectedCategoryList.Count >= 1) { isdeleted = objBLL.DeleteItemDetails(selectedCategoryList); gvItemList.DataSource = objBLL.GetItemDetails(Convert.ToInt32(ddlCategory.SelectedValue)); gvItemList.DataBind(); BindGridView(); if (isdeleted) { lblMessage.Text = "Deleted Successfully"; } else { lblMessage.Text = "Error"; } } else { lblMessage.Text = "Please select item to be deleted"; } } } catch (Exception ex) { lblMessage.Text = "An error occurred while deleting item details"; } finally { objBLL = null; } }