binding datasource to dropdownlist control

Discussion in 'ASP .Net' started by DesignerX, Jul 21, 2003.

  1. DesignerX

    DesignerX Guest

    I am being sent an ArrayList of ListItems.

    I can bind to a dropdownlist control using:

    oDropDownList.DataSource = oArrayList

    This works but when the dropdownlist is rendered both the select box value
    and the text are the same (The ListItem.Text), How do I get the
    ListItem.Text to render as the text and the ListItem.Value to be the html
    select option 'value'?

    Thank You,
    Stan
     
    DesignerX, Jul 21, 2003
    #1
    1. Advertising

  2. DesignerX

    Saravana Guest

    Use DataTextField and DataValueField properties of dropdownlist to assign
    text and value for dropdownlist.

    --
    Saravana
    Microsoft India Community Star,
    MCAD,SE,SD,DBA.


    "DesignerX" <> wrote in message
    news:...
    > I am being sent an ArrayList of ListItems.
    >
    > I can bind to a dropdownlist control using:
    >
    > oDropDownList.DataSource = oArrayList
    >
    > This works but when the dropdownlist is rendered both the select box value
    > and the text are the same (The ListItem.Text), How do I get the
    > ListItem.Text to render as the text and the ListItem.Value to be the html
    > select option 'value'?
    >
    > Thank You,
    > Stan
    >
    >
     
    Saravana, Jul 22, 2003
    #2
    1. Advertising

  3. DesignerX

    DesignerX Guest

    Saravana,

    Thanks for the reply, unfortunately that is my problem... I do not know how
    to use the DataValueField property without looping thru the entire
    ArrayList. With an ArrayList of ListItems, how would I use the
    DataValueField to refer property to refer to a property of the object within
    the array?

    Thanks,
    Stan

    "Saravana" <> wrote in message
    news:...
    > Use DataTextField and DataValueField properties of dropdownlist to assign
    > text and value for dropdownlist.
    >
    > --
    > Saravana
    > Microsoft India Community Star,
    > MCAD,SE,SD,DBA.
    >
    >
    > "DesignerX" <> wrote in message
    > news:...
    > > I am being sent an ArrayList of ListItems.
    > >
    > > I can bind to a dropdownlist control using:
    > >
    > > oDropDownList.DataSource = oArrayList
    > >
    > > This works but when the dropdownlist is rendered both the select box

    value
    > > and the text are the same (The ListItem.Text), How do I get the
    > > ListItem.Text to render as the text and the ListItem.Value to be the

    html
    > > select option 'value'?
    > >
    > > Thank You,
    > > Stan
    > >
    > >

    >
    >
     
    DesignerX, Jul 22, 2003
    #3
  4. DesignerX

    HemaRitchie

    Joined:
    Dec 29, 2008
    Messages:
    3
    a sample code for u DesignerX

    DropDownList1.DataValueField = dtCategoriesList.Columns["categoryID"].ColumnName.ToString();
    DropDownList1.DataTextField = dtCategoriesList.Columns["categoryName"].ColumnName.ToString();
    DropDownList1.DataBind();


    __________________
    HemaRitchie
    realchennai.com/hema
     
    HemaRitchie, Dec 29, 2008
    #4
  5. DesignerX

    HemaRitchie

    Joined:
    Dec 29, 2008
    Messages:
    3
    oops!! add one more line b4 the above mentioned code

    a sample code for u DesignerX

    DropDownList1.DataSource = dtCategoriesList;


    __________________
    HemaRitchie
    realchennai.com/hema
     
    HemaRitchie, Dec 29, 2008
    #5
  6. DesignerX

    HemaRitchie

    Joined:
    Dec 29, 2008
    Messages:
    3
    happy coding :)
     
    HemaRitchie, Dec 29, 2008
    #6
    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. suzy

    binding xml as datasource

    suzy, Apr 11, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    406
  2. John Chambers
    Replies:
    1
    Views:
    442
    Dave Brown
    Mar 21, 2005
  3. Mr Not So Know It All

    Binding multiple Datasource to DropDownlist

    Mr Not So Know It All, Jan 3, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    722
    Mr Not So Know It All
    Jan 3, 2007
  4. Replies:
    1
    Views:
    602
    Ben Rush
    Apr 6, 2007
  5. John Padilla

    DropDownList Binding to LINQ DataSource

    John Padilla, Dec 15, 2007, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    219
    John Padilla
    Dec 15, 2007
Loading...

Share This Page