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

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. Carl Prothman [MVP]

    Re: ASP.NET not set up properly

    Carl Prothman [MVP], Aug 12, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    536
    bhale
    Aug 12, 2003
  2. Jon Maz
    Replies:
    0
    Views:
    517
    Jon Maz
    Aug 24, 2003
  3. Parodi Development
    Replies:
    0
    Views:
    3,950
    Parodi Development
    Sep 10, 2004
  4. =?Utf-8?B?UkY=?=

    Concatenating Multiple Values for DataValueField

    =?Utf-8?B?UkY=?=, Dec 2, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    7,671
    Marina
    Dec 3, 2004
  5. =?Utf-8?B?U3VuaWwgU2FiaXI=?=

    Advantage of DataValueField

    =?Utf-8?B?U3VuaWwgU2FiaXI=?=, Feb 1, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    3,722
    Eliyahu Goldin
    Feb 1, 2005
  6. Vincent
    Replies:
    1
    Views:
    2,951
    Vincent
    Nov 6, 2008
  7. David C

    Object reference not set in ddl

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