Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a gridview in my form,in which there is dropdownlist that is fill up using following code
C#
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,
C#
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
C#
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");
Posted
Comments
Sinisa Hajnal 21-Sep-15 2:29am    
You're binding the list to the control. The controls shows you exactly what is in the list. The solution is simple. Bind to the copy of the list and remove from the original list.
Sajid227 21-Sep-15 3:12am    
plz any code help may you have in this way?
Member 11458121 23-Sep-15 2:32am    
change AppendDataBoundItems="True" into "false"

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900