populating a dropdown list from arraylist of objects

P

Paul M

hi there,

i have an arraylist which holds my Customer object, that contains the
customer details, but when i try binding it to a dropdown box, i cant get
the values to appear..

this is what i tried:

customerList.DataSource = Customer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = CType(customerList.DataSource,
Customer).Email.ToString
customerList.DataValueField = CType(customerList.DataSource,
Customer).CustomerID.ToString
customerList.Items.Insert(0, "-----ALL CUSTOMERS-----")

this error returns me a invalid cast error..so i also tried the normal
method:


customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataBind()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.Items.Insert(0, "-----ALL CUSTOMERS-----")


but this populates the dropdown list with the the values
"Web2004.Customer" - which is my application namespace.Object...??
any help appreciated,

Paul.
 
R

Rick Spiewak

Rearrange the order of your code:
customerList.DataSource = DotcoCustomer.GetAdminList()
customerList.DataTextField = "email"
customerList.DataValueField = "customerID"
customerList.DataBind()
customerList.Items.Insert(0, "-----ALL CUSTOMERS-----")
 

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

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,015
Latest member
AmbrosePal

Latest Threads

Top