Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - Create SelectList

 
Thread Tools Search this Thread
Old 09-07-2008, 03:14 PM   #1
Default Create SelectList


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
  Reply With Quote
Old 09-07-2008, 10:24 PM   #2
shapper
 
Posts: n/a
Default Re: Create SelectList
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
  Reply With Quote
Old 09-08-2008, 12:11 PM   #3
shapper
 
Posts: n/a
Default Re: Create SelectList
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
  Reply With Quote
Old 09-08-2008, 01:04 PM   #4
shapper
 
Posts: n/a
Default Re: Create SelectList
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
  Reply With Quote
Old 09-08-2008, 01:04 PM   #5
shapper
 
Posts: n/a
Default Re: Create SelectList
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
  Reply With Quote
Old 09-08-2008, 05:11 PM   #6
bruce barker
 
Posts: n/a
Default RE: Create SelectList
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
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

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

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46