Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   asp.net mvc SelectList help (http://www.velocityreviews.com/forums/t699933-asp-net-mvc-selectlist-help.html)

rodchar 09-30-2009 12:58 PM

asp.net mvc SelectList help
 
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.GridPageSiz e", Model.GridSizes)%>

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

thanks,
rodchar


Gregory A. Beamer 09-30-2009 03:27 PM

Re: asp.net mvc SelectList help
 
=?Utf-8?B?cm9kY2hhcg==?= <rodchar@discussions.microsoft.com> wrote in
news:0A0A6F9C-E63F-4BB9-A9E2-DE257F519C33@microsoft.com:

> <%= Html.DropDownList("UserProfileSettings.GridPageSiz e",
> 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 09-30-2009 04:02 PM

Re: asp.net mvc SelectList help
 
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==?= <rodchar@discussions.microsoft.com> wrote in
> news:0A0A6F9C-E63F-4BB9-A9E2-DE257F519C33@microsoft.com:
>
> > <%= Html.DropDownList("UserProfileSettings.GridPageSiz e",
> > 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 09-30-2009 04:11 PM

Re: asp.net mvc SelectList help
 
=?Utf-8?B?cm9kY2hhcg==?= <rodchar@discussions.microsoft.com> wrote in
news:1AFAA409-2EE6-4477-AC14-EA04304F74E4@microsoft.com:

> 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 09-30-2009 04:22 PM

Re: asp.net mvc SelectList help
 
Thanks for the help and insight.

"Gregory A. Beamer" wrote:

> =?Utf-8?B?cm9kY2hhcg==?= <rodchar@discussions.microsoft.com> wrote in
> news:1AFAA409-2EE6-4477-AC14-EA04304F74E4@microsoft.com:
>
> > 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! |
> *******************************************
>



All times are GMT. The time now is 10:16 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.