#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2005
    Posts
    13
    Rep Power
    0

    Multiple select options to an array


    I haven't used ASP in ages and can't remember how to do a thing. I have a select listbox in a form, and need each option to hold two pieces of information, a name and an email address. I remember something about having the value of the option be something like "name,email".

    upon submittal, I have some CDO mail functions that needs to pull out the email that was Selected, and the name value to be placed in the email body. Can someone point me to a resource showing how to pull those values out so I can assign them to a variable? No amount of Googling has helped me find an answer!
  2. #2
  3. No Profile Picture
    Grumpier old Moderator
    Devshed Supreme Being (6500+ posts)

    Join Date
    Jun 2003
    Posts
    14,527
    Rep Power
    4541
    I have no idea if this will help you: https://msdn.microsoft.com/en-us/lib...exchg.10).aspx
    ======
    Doug G
    ======
    I've never been able to appreciate the sublime arrogance of folks who feel they were put on earth just to save other folks from themselves .." - Donald Hamilton
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2014
    Posts
    40
    Rep Power
    3
    Just to recap, an MVC Html.DropDownList helper is rendered to the browser as an HTML <select> element. They are mainly employed to provide the user with a means to select one of a number of options. Multiple selection select elements are useful when you want to provide your user with a means to choose more then one option but you do not want to use checkboxes, for example. You can enable multiple selection in one of two ways: you can add the multiple attribute to the Html.DropDownList helper via its htmlAttributes parameter, or you can use the Html.ListBox (or Html.ListBoxFor) helper. Options can be passed to the helper in a number of forms: as an Enumerable<SelectListItem>; as a SelectList object or as a MultiSelectList object:
    Code:
    using (var db = new NorthwindContext())
    {
        var categories = db.Categories.Select(c => new { 
            CategoryID = c.CategoryID, 
            CategoryName = c.CategoryName 
        }).ToList();
        ViewBag.Categories = new MultiSelectList(categories, "CategoryID", "CategoryName");
        return View();
    }

    @Html.DropDownList("CategoryId", (MultiSelectList)ViewBag.Categories, new { multiple = "multiple"})
    @Html.ListBox("CategoryId", (MultiSelectList)ViewBag.Categories)

    Both helpers will result in identical HTML:
    Code:
    <select id="CategoryId" multiple="multiple" name="CategoryId">
        <option value="1">Beverages</option>
        <option value="2">Condiments</option>
        <option value="3">Confections</option>
        <option value="4">Dairy Products</option>
        <option value="5">Grains/Cereals</option>
        <option value="6">Meat/Poultry</option>
        <option value="7">Produce</option>
        <option value="8">Seafood</option>
    </select>

IMN logo majestic logo threadwatch logo seochat tools logo