Click here to Skip to main content
15,914,014 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how can i remove remove an item from the drop down list once an item has been selected from it in asp.net mvc4? See the process is having a list of conferences and a list of developers now you must select any conference and add a developer to it but i mustnt be able to add the developer twice to the conference? I want to know whether you can do this or whether there is validation for this? This is my controller:

public class ConferenceAttendantController : Controller
{
private PrjctMngmt2Entities db = new PrjctMngmt2Entities();

//
// GET: /ConferenceAttendants/

public ViewResult Index()
{
var ConferenceAttendants = db.ConferenceAttendants.Include("Conference").Include("Developer");
return View(ConferenceAttendants.ToList());
}

//
// GET: /ConferenceAttendants/Create

public ActionResult Create()
{
ViewBag.ConferenceID = new SelectList(db.Conferences.OrderBy(d => d.Name), "ConferenceID", "Name");
ViewBag.DeveloperID = new SelectList(db.Developers.Select(d => new { d.DeveloperID, DeveloperName = d.FirstName + " " + d.LastName }).OrderBy(d => d.DeveloperName), "DeveloperID", "DeveloperName");
return View();
}

//
// POST: /ConferenceAttendants/Create

[HttpPost]
public ActionResult Create(ConferenceAttendant ConferenceAttendant)
{
if (ModelState.IsValid)
{
db.ConferenceAttendants.Add(ConferenceAttendant);
db.SaveChanges();
return RedirectToAction("Index", "Conference");
}
return View();
}
Posted

Generally, you don't. Users don't expect items to disappear from a drop down list, so please don't do it that way.

You could try using a checked list box for selecting the developers. Or, the more usual, two lists with > (add) and < (remove) buttons between them.
 
Share this answer
 
you can remove the particular selected item from the drop down list and rebind the datasource to the new updates record set.
 
Share this answer
 

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