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

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marina
    Replies:
    0
    Views:
    949
    Marina
    Aug 12, 2003
  2. Parodi Development
    Replies:
    0
    Views:
    3,718
    Parodi Development
    Sep 10, 2004
  3. Vincent
    Replies:
    1
    Views:
    2,799
    Vincent
    Nov 6, 2008
  4. David C

    Object reference not set in ddl

    David C, Jan 14, 2009, in forum: ASP .Net
    Replies:
    1
    Views:
    336
    David C
    Jan 14, 2009
  5. Replies:
    3
    Views:
    109
    Thomas 'PointedEars' Lahn
    Dec 6, 2007
Loading...

Share This Page