如何在GridView中删除或添加员工到DropDownList [英] How To Remove Or Add Employee To the DropDownList In GridView

查看:61
本文介绍了如何在GridView中删除或添加员工到DropDownList的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用以下代码绑定网格视图下拉列表中的数据

I am using following code to bind data in grid view dropdownlist

protected void OnRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {            
                  
                CheckBox CHKBOX = (e.Row.FindControl("Released") as CheckBox);
                CheckBox CHKBOX1 = (e.Row.FindControl("Released1") as CheckBox);
                    DropDownList ddlEmployee = (e.Row.FindControl("ddlEmp") as DropDownList);
                    DropDownList ddlEmployee2 = (e.Row.FindControl("ddlEmp2") as DropDownList);
                    var emp1 = _service.GetEmployeeDutyByEmployee_Id(MyUser.Employee_Id).LastOrDefault();
                    var EmpList = _service.GetAllEmployeeDuty().OrderByDescending(x => x.EndDate).GroupBy(x => x.Employee_Id).Select(x => x.First()).ToList();
                    var empList = EmpList.Where(X => X.ToSector_Id == emp1.ToSector_Id).ToList();
                    ddlEmployee.Bind(empList, "EmployeeIdName", "Employee_Id");
                    ddlEmployee2.Bind(empList, "EmployeeIdName", "Employee_Id");
                  
            }
        }



并使用以下代码保存值


and use following code to save the values

protected void ddlEmp_SelectedIndexChanged(object sender, EventArgs e)
           {
               Entities entities = new Entities();

               Control row = ((Control)sender).NamingContainer;
               DropDownList ddlEmp = (DropDownList)row.FindControl("ddlEmp");
               DropDownList ddlEmp2 = (DropDownList)row.FindControl("ddlEmp2");
               Label lblPointName = (Label)ddlEmp.NamingContainer.FindControl("lblPointName");
               Label lblPointName1 = (Label)ddlEmp.NamingContainer.FindControl("lblPointName1");
               string Emp1 = ddlEmp.SelectedValue;
               string Emp2 = ddlEmp2.SelectedValue;
               string pointname = lblPointName.Text;
               string pointname1 = lblPointName1.Text;

                   var PointIdByName = (from mdp in entities.SectorWisePoints.Where(x => x.Name == pointname) select mdp).Single();
                   var EmployeeById = (from ebi in entities.ModifiedNames.Where(x => x.BeltNo == Emp1) select ebi).Single();
                   CTP.HRMS.Business.DailyManualRoaster dmr = new Business.DailyManualRoaster();
                   dmr.SectorWisePoint_Id = PointIdByName.Id;
                   dmr.Employee_Id = EmployeeById.BeltNo;
                   dmr.ManDailyRoasterDate = DateTime.Now;
                   dmr.Sector_Id = 1;
                   _service.InsertDailyManualRoaster(dmr);



               }



1.i希望员工一旦被删除就会被删除列表中的员工。

2.i当用户点击此框时,每行都有一个复选框,此行的员工已经保存,将从数据库中删除并再次添加到下拉列表中?


1.i want that when an employee is saved once it will remove employee from the list.
2.i have a checkbox along each row when user click on this box the employee against this row that is save already ,will be deleted from database and again add to list of dropdown?

推荐答案

- 删除或添加员工到数据库。

- 成功后,再次从db获取员工。

- 将更新后的员工从db绑定到下拉列表数据源,然后就完成了。
- Delete or add employee from-to the db.
- After success, just get the employees from db once more.
- Bind the updated employees from db to the dropdownlist datasource and you are done.


这篇关于如何在GridView中删除或添加员工到DropDownList的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆