Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Dan 1288 posts 3921 karma points c-trib
    Dec 10, 2010 @ 17:30
    Dan
    0

    Get custom dropdown list options programatically

    Hi,

    I'm trying to extend a .NET membership registration control with some custom member type properties.  One of these properties is a drop-down list.  I've read a post about using Prevalues.GetPrevalues but am struggling with the syntax to bind this to the dropdownlist control in my form.

    Can anyone point me in the right direction here?

    Thanks.

  • Dan 1288 posts 3921 karma points c-trib
    Dec 10, 2010 @ 18:38
    Dan
    0

    Okay, here's where I'm at:

    protected void Page_Load(object sender, EventArgs e)
    {
    DropDownList TypeOfUserDropDown = (DropDownList)CreateUserWizard1.CreateUserStep.ContentTemplateContainer.FindControl("TypeOfUser");

    var TypeOfUserOptions = PreValues.GetPreValues(5611);
    for (int i = 0; i < TypeOfUserOptions.Count; i++){
    TypeOfUserDropDown.Items.Add(new ListItem());
    }
    }

    It feels like I'm getting close, but I just don't know how to get the values to populate the drop-down.  Am I on the right lines here?

  • Dan 1288 posts 3921 karma points c-trib
    Dec 14, 2010 @ 11:00
    Dan
    0

    Sorry to bump this folks, but my .NET skills aren't the best, and I'm picking this up again after struggling with it for way too long!  Anyone have any pointers at all?

  • Dirk De Grave 4541 posts 6021 karma points MVP 3x admin c-trib
    Dec 14, 2010 @ 12:24
    Dirk De Grave
    0

    PreValues.GetPrevalues returns a SortedList, so you'd have to iterate those using a enumerator. Code snippet should get you started:

    SortedList typesOfUser = PreValues.GetPreValues(5611);
    IDictionaryEnumerator ide = typesOfUser.GetEnumerator();
    while (ide.MoveNext()) { PreValue typeOfUser = (PreValue)ide.Value; TypeOfUsersDropDown.Items.Add(new ListItem(typeOfUser.Value, typeOfUser.Id.ToString()); }

    Hope this helps.

     

    Regards,

    /Dirk

     

  • Dan 1288 posts 3921 karma points c-trib
    Dec 15, 2010 @ 11:42
    Dan
    0

    Hi Dirk,

    Thanks LOADS for this.  I'd been through something very much like it (and a million other variations) on my way to my code above, but I'd always got errors on compilation (usually regarding 'SortedList' requiring two parameters).  Since you suggested this again I looked a lot harder into the errors this time and found the root of my problems: I was including the 'using System.Collections.Generic;' namespace rather than 'using System.Collections;'.  This has sorted it.

    I believe the phrase is H5YR! :)

Please Sign in or register to post replies

Write your reply to:

Draft