Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Web Controls > DDL DataValueField does not set properly

Thread Tools

DDL DataValueField does not set properly

Posts: n/a
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

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

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.

Reply With Quote

Thread Tools

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
Object reference not set in ddl David C ASP .Net 1 01-14-2009 09:44 PM
DropDownList in Gridview when item does not exist in ddl Vincent ASP .Net 1 11-06-2008 09:59 PM
Prototype.js does not set objects's constructor property properly Javascript 3 12-06-2007 07:52 PM
DropdownList, DataValueField, DataTextField and Custom Collections.. Parodi Development ASP .Net 0 09-10-2004 06:29 PM
Re: Persisting DDL.SelectedValue or DDL.SelectedItem.Value without Viewstate Marina ASP .Net 0 08-12-2003 07:08 PM