Sajid Hussain

Sajid Hussain

  • NA
  • 346
  • 48.6k

How To Remove Or Add Employee To the DropDownList In GridVie

Sep 16 2015 4:03 AM
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
Hide Copy Code
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 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?