Reputation: 37
how to remove selected value from drop downs.
here is my code.
@viewbag.empskil = new selectlist(db.skils,"skillid","skillname");
my view code
@html.Dropdown("skill", @viewbag.empskil as SelectList);
It Showing all skill in drop down An Employee can Have multiple Skill. multiple skill are adding with rating .
I just Want to remove Already Selected Skill From Drop down. can anybody tell me how to accomplish this
here is the screen
I just want if employee having skill these skill will not show in drop down.can any body tell me how it will be done.
Upvotes: 0
Views: 2287
Reputation: 12174
Sounds like you will need both server-side and client-side code. Server-side, take a list of all skills and a list of employee skills and create a new list using LINQs "Except", something like:
var unusedSkills = db.skils.ToList().Except(db.empSkils);
@viewbag.empskil = new selectlist(unusedSkills,"skillid","skillname");
Client-side, you'll want to use jQuery to remove a skill from the list after it is selected and add it to the employee's list, something like:
$("#button1").click(function(){
$("#list1 > option:selected").each(function(){
$(this).remove().appendTo("#list2");
});
});
Upvotes: 1