Sajid Hussain

Sajid Hussain

  • 1.2k
  • 514
  • 99.2k

How to update dropdownlist in gridview

Sep 19 2015 6:06 AM
I have a gridview in my form,in which there is dropdownlist that is fill up using following code
Hide Copy Code
DropDownList ddlEmployee = (DropDownList)row.FindControl("ddlEmp");            
       DropDownList ddlEmployee2 = (DropDownList)row.FindControl("ddlEmp2");      
             var Emplist1 = _service.GetAllSectorEmployee();                  
 ddlEmployee.Bind(Emplist1, "EmployeeIdName", "Employee_Id");                
   ddlEmployee2.Bind(Emplist1, "EmployeeIdName", "Employee_Id"); 
i have a requirement that when ever employee is selected ,then it will remove from list,i have done it using following code,
Hide Copy Code
var removelist = _service.GetAllSectorEmployee().Where(x => x.Employee_Id == Emp2).FirstOrDefault();   
                     _service.DeleteSectorEmployee(removelist); 
problem is that when employee is removed ,dropdownlist will be updated and also remove that employee.how can i do it? i try following code but fruitless
Hide Copy Code
DropDownList ddlEmployee = (DropDownList)row.FindControl("ddlEmp");    

                     DropDownList ddlEmployee2 = (DropDownList)row.FindControl("ddlEmp2");         
                var Emplist1 = _service.GetAllSectorEmployee();                     
    ddlEmployee.Bind(Emplist1, "EmployeeIdName", "Employee_Id");                  
       ddlEmployee2.Bind(Emplist1, "EmployeeIdName", "Employee_Id");

Answers (4)