PC Review


Reply
Thread Tools Rate Thread

Create SelectList

 
 
shapper
Guest
Posts: n/a
 
      7th Sep 2008
Hello,

I am creating a select list as follows:

new SelectList(new[] { "a", "b"})

How can I create the same list but with different name and value for
each item?

Thanks,
Miguel
 
Reply With Quote
 
 
 
 
shapper
Guest
Posts: n/a
 
      7th Sep 2008
On Sep 7, 8:36*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "shapper" <mdmo...@gmail.com> wrote in message
>
> news:b67ebe99-f95f-4cc5-8084-(E-Mail Removed)...
>
> > How can I create the same list but with different name and value for
> > each item?

>
> I don't understand what you mean... How can it be the same list if it has
> different contents...?
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


No ...

I just need to create a SelectList where each ListItem has different
Name and Value ...

For example:

Item 1 > Name = "New York", Value = "NY".

Thanks,
Miguel
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      8th Sep 2008
On Sep 7, 11:36*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "shapper" <mdmo...@gmail.com> wrote in message
>
> news:23aff63d-0d2d-42b7-97b0-(E-Mail Removed)...
>
> >>> How can I create the same list but with different name and value for
> >>> each item?

>
> >> I don't understand what you mean... How can it be the same list if it has
> >> different contents...?

>
> > I just need to create a SelectList where each ListItem has different
> > Name and Value ...

>
> > For example:

>
> > Item 1 > Name = "New York", Value = "NY".

>
> Hmm - are you sure you're not talking about a Dictionary<>...?
>
> Dictionary<string, string> MyDictionary = new Dictionary<string, string>();
> MyDictionary.Add("New York", "NY");
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


I am using this in an DropDownList. Shouldn't be a SelectList?
 
Reply With Quote
 
shapper
Guest
Posts: n/a
 
      8th Sep 2008
On Sep 8, 12:34*pm, "Mark Rae [MVP]" <m...@markNOSPAMrae.net> wrote:
> "shapper" <mdmo...@gmail.com> wrote in message
>
> news:f2d3782c-4e29-45a8-9d9e-(E-Mail Removed)...
>
> >>> Item 1 > Name = "New York", Value = "NY".

>
> >> Hmm - are you sure you're not talking about a Dictionary<>...?

>
> >> Dictionary<string, string> MyDictionary = new Dictionary<string,
> >> string>();
> >> MyDictionary.Add("New York", "NY");

>
> > I am using this in an DropDownList. Shouldn't be a SelectList?

>
> Perhaps we're getting bogged down by nomenclature here... Can you please
> clarify precisely which object you are referring to as a "SelectList"...?
>
> Some of your code would be helpful...
>
> --
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net


Sure.

I am creating in an ASP.NET MVC view a DropDownList:

<%= Html.DropDownList( "", "Cities", new SelectList( new [] { "New
York", "Paris", "London" } ) ) %>

However, I would like each item to have a name different from its
value. For example:
"New York" would display as "New York" but the value would be "NY".

Thanks,
Miguel
 
Reply With Quote
 
bruce barker
Guest
Posts: n/a
 
      8th Sep 2008
the SelectList supports any enumerable list. if you want an id and value in
the constructor you specifiy a DataValueField and a DataTextField. as eval
is done, you don't need to a use a data record, any object will do. try:

new SelectList(new[]
{
new (ID = "1" Value = "a"},
new {ID = "2" Value ="b"}
),
"ID","Value);

-- bruce (sqlwork.com)


"shapper" wrote:

> Hello,
>
> I am creating a select list as follows:
>
> new SelectList(new[] { "a", "b"})
>
> How can I create the same list but with different name and value for
> each item?
>
> Thanks,
> Miguel
>

 
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
asp.net mvc SelectList help rodchar Microsoft ASP .NET 4 30th Sep 2009 05:22 PM
how to create an auto reply rule/macro that wont create a new mess squalltheonly Microsoft Outlook Discussion 4 15th Nov 2008 04:03 PM
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 user on win2k domain does not create mailbox on ex2k server Jeff Howard Microsoft Windows 2000 0 1st Oct 2003 12:21 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:41 AM.