PC Review


Reply
Thread Tools Rate Thread

asp.net mvc SelectList help

 
 
rodchar
Guest
Posts: n/a
 
      30th Sep 2009
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

 
Reply With Quote
 
 
 
 
Gregory A. Beamer
Guest
Posts: n/a
 
      30th Sep 2009
=?Utf-8?B?cm9kY2hhcg==?= <(E-Mail Removed)> wrote in
news:0A0A6F9C-E63F-4BB9-A9E2-(E-Mail Removed):

> <%= 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! |
*******************************************
 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      30th Sep 2009
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==?= <(E-Mail Removed)> wrote in
> news:0A0A6F9C-E63F-4BB9-A9E2-(E-Mail Removed):
>
> > <%= 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! |
> *******************************************
>

 
Reply With Quote
 
Gregory A. Beamer
Guest
Posts: n/a
 
      30th Sep 2009
=?Utf-8?B?cm9kY2hhcg==?= <(E-Mail Removed)> wrote in
news:1AFAA409-2EE6-4477-AC14-(E-Mail Removed):

> 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! |
*******************************************
 
Reply With Quote
 
rodchar
Guest
Posts: n/a
 
      30th Sep 2009
Thanks for the help and insight.

"Gregory A. Beamer" wrote:

> =?Utf-8?B?cm9kY2hhcg==?= <(E-Mail Removed)> wrote in
> news:1AFAA409-2EE6-4477-AC14-(E-Mail Removed):
>
> > 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! |
> *******************************************
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SelectList. How to find value? shapper Microsoft C# .NET 0 17th Sep 2008 12:39 AM
SelectList. What am i doing wrong? shapper Microsoft C# .NET 0 16th Sep 2008 11:35 PM
Create SelectList shapper Microsoft ASP .NET 4 8th Sep 2008 05:11 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:35 AM.