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
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