DropdownList, DataValueField, DataTextField and Custom Collections..

Discussion in 'ASP .Net' started by Parodi Development, Sep 10, 2004.

  1. Hi,

    I have a Custom Collection (derived from NameValueCollection) that contains
    Items of type Person with 3 properties : Name, Surname, DateOfBirth.

    I use the following code :

    PersonCollection pCol = new PersonCollection();
    .... Fill Collection with Person objects..

    Then in a WebPage with a DropdownList named dropDown1 I use :

    private void page_load()
    {
    dropDown1.DataSource = pcol;
    dropDown1.DataTextValue = "Name";
    dropDown1.DataFieldValue = "DateOfBirth"
    dropDown1.DataBind();
    }

    And I still can't get it to work.. Any idea on how to bind a custom
    collection to a dropdownList and then specify which property to have
    displayed as text in the dropdown and which property to store the value I
    need to get back after user selection ???

    Thanks in advance.
     
    Parodi Development, Sep 10, 2004
    #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. Sam
    Replies:
    1
    Views:
    12,116
    Eliyahu Goldin
    Feb 18, 2005
  2. tshad
    Replies:
    3
    Views:
    4,659
    tshad
    May 10, 2005
  3. Eric W. Holzapfel

    Access DropDownlist datavaluefield value

    Eric W. Holzapfel, Jan 1, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    16,211
    =?Utf-8?B?RWx0b24gVw==?=
    Jan 1, 2006
  4. jobs
    Replies:
    0
    Views:
    499
  5. Darrin

    XML Dropdownlist- Custom DataTextField

    Darrin, Jun 22, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    348
    Phillip Williams
    Jun 22, 2006
Loading...

Share This Page