Using a Class enumeration as a Data Source

D

dwok

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
 
G

Guest

Hi,
Try this..
Dim t1 As Type = GetType(Phone.PhoneNumberType)
dropDownListBox.DataSource = System.Enum.GetValues(t1)
dropDownListBox.DataBind();
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top