![]() |
|
|
|
#1 |
|
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 shapper |
|
|
|
|
#2 |
|
Posts: n/a
|
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-... > > > 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 shapper |
|
|
|
#3 |
|
Posts: n/a
|
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-... > > >>> 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? shapper |
|
|
|
#4 |
|
Posts: n/a
|
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-... > > >>> 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 shapper |
|
|
|
#5 |
|
Posts: n/a
|
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-... > > >>> 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 shapper |
|
|
|
#6 |
|
Posts: n/a
|
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 > bruce barker |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to burn copy CD/DVD and create Data/Audio/Video Disc? | dvdloveri | Software | 6 | 07-27-2009 07:58 AM |
| how to create os image in same drive using symantech ghost 11. | manojgj | Hardware | 0 | 02-28-2008 08:47 AM |
| How to create a short clip from a .VOD file? | zalek | DVD Video | 3 | 01-24-2007 06:50 PM |
| MovieFactory 5: is it possible to create a VOB file? URGENT!! | ijones@iTOGLIinterfree.it | DVD Video | 0 | 07-09-2006 09:44 AM |
| Press Release - Visual CertExam Suite Makes It Easy to Create and Take Professional Practice Tests | David Johnson | A+ Certification | 0 | 10-19-2004 05:03 PM |