DDL DataValueField does not set properly

P

PopMan

Hi, I'm binding a DataSet to a DropDownList control which works fine. What
doesn't work is the DataValueField. Here's my code (C#) on the Page_Load
event:

SomeClass A = new SomeClass();
DataSet myDS = new DataSet();

myDS = A.GetEmployeesDS(); // the A object has a method which returns a
DataSet object
myDDL.DataSource = myDS;
myDDL.DataMember="EmployeesTable"; // the table name from which
data originates (do I need this?)
myDDL.DataTextField = "EmployeeName"; // column which contains text
to display
myDDL.DataValueField = "EmployeeID"; // column which contains a
unique ID
myDDL.DataBind();

The result is that the DDL's DataTextField is populated with the data from
the DataSet, but the DataValueField holds the value "EmployeeID" for all
items in the DDL. I'm not sure why it treats EmployeeID as a literal and
EmployeeName as a column/data. Even if I remove the line of code where I set
the DataMember, it displays the EmployeeName. Am I missing anything?

Thank you for you help.
Peter
 

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

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top