Пример #1
0
        /// <summary>
        /// Function to delete an employee from the list.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void btnDelete_Click(object sender, EventArgs e)
        {
            IAdminBLL objBLL = AdminBLLFactory.CreateAdminBLLObject();

            try
            {
                bool       isEmployeeSelected = false;
                bool       isDeleted          = false;
                List <int> selectedItemList1  = new List <int>();


                //loop through the grid to find the selected item
                for (int i = 0; i < gvManageEmployee.Rows.Count; i++)
                {
                    GridViewRow gvEmployeeRow = gvManageEmployee.Rows[i];
                    isEmployeeSelected = (Boolean)((CheckBox)gvEmployeeRow.FindControl("chkSelect")).Checked;
                    if (isEmployeeSelected)
                    {
                        selectedItemList1.Add(Convert.ToInt32(gvManageEmployee.Rows[i].Cells[1].Text));
                    }
                }
                if (selectedItemList1.Count == 0)
                {
                    lblMessage.Text = "Please select employee";
                }
                else
                {
                    isDeleted = objBLL.DeleteEmployeeDetails(selectedItemList1);
                    gvManageEmployee.DataSource = objBLL.GetEmployeeDetailsList();
                    gvManageEmployee.DataBind();


                    //if (isEmployeeSelected)
                    //{
                    //    lblMessage.Text = "Please select an employee";
                    //}
                    if (isDeleted)
                    {
                        lblMessage.Text = "Employee(s) deleted successfully";
                    }
                }
            }
            catch (Exception ex)
            {
                lblMessage.Text = ex.Message;
            }
        }