asp.net mvc SelectList help

Discussion in 'ASP .Net' started by rodchar, Sep 30, 2009.

  1. rodchar

    rodchar Guest

    Hi All,

    I'm trying to bind a simple selectlist to my html.dropdownlist but not so
    simple for me. I have this so far:

    MODEL:
    private void LoadDropDownLists(MorrisExpressContext
    morrisExpressContext)
    {
    Dictionary<string, int> ddl = new Dictionary<string, int>();
    ddl.Add("Select...", -1);
    ddl.Add("15 Minutes", 15);
    ddl.Add("30 Minutes", 30);
    ddl.Add("60 Minutes", 60);
    GridSizes = new SelectList(ddl);
    }
    VIEW:
    <%= Html.DropDownList("UserProfileSettings.GridPageSize", Model.GridSizes)%>

    RESULT:
    [Select..., -1] is showing up in the dropdownlist (including the brackets)
    instead of just showing the text part?

    thanks,
    rodchar
    rodchar, Sep 30, 2009
    #1
    1. Advertising

  2. =?Utf-8?B?cm9kY2hhcg==?= <> wrote in
    news::

    > <%= Html.DropDownList("UserProfileSettings.GridPageSize",
    > Model.GridSizes)%>


    Have you ensured that you have bound GridSizes to the model?

    Peace and Grace,

    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Sep 30, 2009
    #2
    1. Advertising

  3. rodchar

    rodchar Guest

    found snippet that worked:

    AppointmentDurations = new SelectList(
    new[]
    {
    new { Value = 15, Name = "15 Minutes" },
    new { Value = 30, Name = "30 Minutes" },
    new { Value = 60, Name = "60 Minutes" }
    }
    , "Value", "Name");

    btw, what does new[] mean?



    "Gregory A. Beamer" wrote:

    > =?Utf-8?B?cm9kY2hhcg==?= <> wrote in
    > news::
    >
    > > <%= Html.DropDownList("UserProfileSettings.GridPageSize",
    > > Model.GridSizes)%>

    >
    > Have you ensured that you have bound GridSizes to the model?
    >
    > Peace and Grace,
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
    >
    rodchar, Sep 30, 2009
    #3
  4. =?Utf-8?B?cm9kY2hhcg==?= <> wrote in
    news::

    > found snippet that worked:
    >
    > AppointmentDurations = new SelectList(
    > new[]
    > {
    > new { Value = 15, Name = "15 Minutes" },
    > new { Value = 30, Name = "30 Minutes" },
    > new { Value = 60, Name = "60 Minutes" }
    > }
    > , "Value", "Name");
    >
    > btw, what does new[] mean?.


    Essentially, the code states:

    Set up a new Select List and load it with a new array with 3 name value
    pairs.

    The new[] states that you are creating the class array.

    peace and grace,


    --
    Gregory A. Beamer
    MVP; MCP: +I, SE, SD, DBA

    Twitter: @gbworld
    Blog: http://gregorybeamer.spaces.live.com

    *******************************************
    | Think outside the box! |
    *******************************************
    Gregory A. Beamer, Sep 30, 2009
    #4
  5. rodchar

    rodchar Guest

    Thanks for the help and insight.

    "Gregory A. Beamer" wrote:

    > =?Utf-8?B?cm9kY2hhcg==?= <> wrote in
    > news::
    >
    > > found snippet that worked:
    > >
    > > AppointmentDurations = new SelectList(
    > > new[]
    > > {
    > > new { Value = 15, Name = "15 Minutes" },
    > > new { Value = 30, Name = "30 Minutes" },
    > > new { Value = 60, Name = "60 Minutes" }
    > > }
    > > , "Value", "Name");
    > >
    > > btw, what does new[] mean?.

    >
    > Essentially, the code states:
    >
    > Set up a new Select List and load it with a new array with 3 name value
    > pairs.
    >
    > The new[] states that you are creating the class array.
    >
    > peace and grace,
    >
    >
    > --
    > Gregory A. Beamer
    > MVP; MCP: +I, SE, SD, DBA
    >
    > Twitter: @gbworld
    > Blog: http://gregorybeamer.spaces.live.com
    >
    > *******************************************
    > | Think outside the box! |
    > *******************************************
    >
    rodchar, Sep 30, 2009
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gianni
    Replies:
    2
    Views:
    860
    Gianni
    Apr 19, 2004
  2. shapper

    Create SelectList

    shapper, Sep 7, 2008, in forum: ASP .Net
    Replies:
    5
    Views:
    719
    bruce barker
    Sep 8, 2008
  3. Crazy Cat
    Replies:
    1
    Views:
    683
    schepp
    Sep 3, 2009
  4. jwcooper

    Mechanize SelectList Issue

    jwcooper, Mar 20, 2007, in forum: Ruby
    Replies:
    1
    Views:
    135
    jwcooper
    Mar 21, 2007
  5. Giel Raijmakers

    popup after selection from selectlist

    Giel Raijmakers, Jan 4, 2008, in forum: Ruby
    Replies:
    0
    Views:
    93
    Giel Raijmakers
    Jan 4, 2008
Loading...

Share This Page