DDL DataValueField does not set properly

Discussion in 'ASP .Net Web Controls' started by PopMan, Aug 21, 2003.

  1. PopMan

    PopMan Guest

    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
     
    PopMan, Aug 21, 2003
    #1
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.