PC Review


Reply
Thread Tools Rate Thread

Using a Class enumeration as a Data Source

 
 
dwok
Guest
Posts: n/a
 
      23rd May 2005
Hello,

I have a class that contains an enumeration and I would like to bind
the members of the enumerations to a drop down list box. If have seen
some examples that use Enum.GetNames and Enum.GetValues but when ever I
pass the name of my enumeration I get an error. Let me illustrate.

--- VB.NET Code ----------

Public Class Phone

Public Enum PhoneNumberType
Home = 1
Work = 2
Mobile = 3
Fax = 4
Pager = 5
End Enum

End Class

--- ASP.NET Code -------

dropDownListBox.DataSource =
System.Enum.GetValues(Phone.PhoneNumberType)

It's here that I get an error. "PhoneNumberType is a type in Phone and
cannot be used as an expression". Any guess on what I might be doing
wrong? Thanks.

-dwok

 
Reply With Quote
 
 
 
 
=?Utf-8?B?RG90TmV0V29ya3M=?=
Guest
Posts: n/a
 
      23rd May 2005
Hi,
Try this..
Dim t1 As Type = GetType(Phone.PhoneNumberType)
dropDownListBox.DataSource = System.Enum.GetValues(t1)
dropDownListBox.DataBind();


"dwok" wrote:

> Hello,
>
> I have a class that contains an enumeration and I would like to bind
> the members of the enumerations to a drop down list box. If have seen
> some examples that use Enum.GetNames and Enum.GetValues but when ever I
> pass the name of my enumeration I get an error. Let me illustrate.
>
> --- VB.NET Code ----------
>
> Public Class Phone
>
> Public Enum PhoneNumberType
> Home = 1
> Work = 2
> Mobile = 3
> Fax = 4
> Pager = 5
> End Enum
>
> End Class
>
> --- ASP.NET Code -------
>
> dropDownListBox.DataSource =
> System.Enum.GetValues(Phone.PhoneNumberType)
>
> It's here that I get an error. "PhoneNumberType is a type in Phone and
> cannot be used as an expression". Any guess on what I might be doing
> wrong? Thanks.
>
> -dwok
>
>

 
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
Enumeration and Class shapper Microsoft C# .NET 4 17th Jun 2009 04:47 PM
LINQ - Removing elements in source list prevents enumeration of "c Todd Beaulieu Microsoft Dot NET 11 7th Mar 2008 08:51 AM
Unable to set the xvalues property of the series class for a single row of source data Sisilla Microsoft Excel Programming 3 11th May 2007 02:34 PM
How DataGridView refresh and update the data source class property run time Ivan Microsoft C# .NET 2 10th Aug 2006 04:52 PM
Using a Class enumeration as a Data Source dwok Microsoft ADO .NET 1 23rd May 2005 09:38 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:12 PM.