binding - DropDownList flaw/bug?

Discussion in 'ASP .Net Web Controls' started by Matthew.DelVecchio@CapitalOneAuto.com, Jun 24, 2005.

  1. Guest

    hey gang,

    ok so i experienced something that doesnt operate as i would have
    expected. in a component i build up a ListItemCollection in function
    ..GetGalleries() like so:


    Dim galleries As New System.Web.UI.WebControls.ListItemCollection

    'loop & add to collection
    Dim node As XmlNode
    For Each node In galleryNodes
    galleries.Add(New ListItem("sometext", "somevalue"))
    Next

    Return galleries

    then, in my application i attempt to bind like so:

    Dim galleries As ListItemCollection = im.GetGalleries(year)

    ddlGallery.DataSource = galleries
    ddlGallery.DataBind()

    ....now, you would think then, that the ddlGallery dropdownlist would
    take the returned ListItemCollection and bind its list items to the
    list. It does -- sort of.. it does, BUT it doesnt use the ".value"
    porton of the returned ListItems ("somevalue"). instead, it just takes
    the ".text" value of each ListItem ("sometext") and sticks that in both
    the text AND the value of each item in ddlGallery. whaaaa?

    clearly, the expected behavior would be for ddlGallery list control to
    see that its getting a ListItemCollection as a datasource, and
    intelligently bind it -- by using the existing .text and .value values
    if of the collection's ListItems... after all, this isnt any ole
    collection, it's a *ListItemCollection*...!

    as a work around, i have to loop thru the returned collection and add
    each individually, like so:

    Dim galleries As ListItemCollection = im.GetGalleriesForYear(year)

    Dim item As ListItem
    For Each item In galleries
    ddlGallery.Items.Add(item)
    Next



    thats pretty lame. can anyone comment on this?

    thanks!
    matt

    --
    Matt Del Vecchio
    , Jun 24, 2005
    #1
    1. Advertising

  2. Harolds Guest

    try this
    ddlGallery.DataSource = galleries
    ddlGallery.DataTextField = "Text"
    ddlGallery.DataValueField = "Value"
    ddlGallery.DataBind()


    "" wrote:

    > hey gang,
    >
    > ok so i experienced something that doesnt operate as i would have
    > expected. in a component i build up a ListItemCollection in function
    > ..GetGalleries() like so:
    >
    >
    > Dim galleries As New System.Web.UI.WebControls.ListItemCollection
    >
    > 'loop & add to collection
    > Dim node As XmlNode
    > For Each node In galleryNodes
    > galleries.Add(New ListItem("sometext", "somevalue"))
    > Next
    >
    > Return galleries
    >
    > then, in my application i attempt to bind like so:
    >
    > Dim galleries As ListItemCollection = im.GetGalleries(year)
    >
    > ddlGallery.DataSource = galleries
    > ddlGallery.DataBind()
    >
    > ....now, you would think then, that the ddlGallery dropdownlist would
    > take the returned ListItemCollection and bind its list items to the
    > list. It does -- sort of.. it does, BUT it doesnt use the ".value"
    > porton of the returned ListItems ("somevalue"). instead, it just takes
    > the ".text" value of each ListItem ("sometext") and sticks that in both
    > the text AND the value of each item in ddlGallery. whaaaa?
    >
    > clearly, the expected behavior would be for ddlGallery list control to
    > see that its getting a ListItemCollection as a datasource, and
    > intelligently bind it -- by using the existing .text and .value values
    > if of the collection's ListItems... after all, this isnt any ole
    > collection, it's a *ListItemCollection*...!
    >
    > as a work around, i have to loop thru the returned collection and add
    > each individually, like so:
    >
    > Dim galleries As ListItemCollection = im.GetGalleriesForYear(year)
    >
    > Dim item As ListItem
    > For Each item In galleries
    > ddlGallery.Items.Add(item)
    > Next
    >
    >
    >
    > thats pretty lame. can anyone comment on this?
    >
    > thanks!
    > matt
    >
    > --
    > Matt Del Vecchio
    >
    >
    Harolds, Jun 24, 2005
    #2
    1. Advertising

  3. Guest

    ah... yes im familar with those properties, however i thought they only
    pertained to the string name of a data column, say from a dataset or
    datatable -- i didnt realize they would accept "Text" and "Value"..!
    that is cool and saves me code. thanks.

    case closed!

    now, does that work only because the ListItemCollection uses "Text" and
    "Value" as internal names? meaning, can this work with say a
    multi-dimensional array, or dictionary object, etc -- other collection
    objects of 2-part items? probably not, because those collection types
    dont have "Text" or "Value" -- in which case, how do we designate...

    what im really getting at, is an XML nodelist... say if i bind a
    nodelist to a DropDownList, im not aware of a way -- even using
    ..DataTextFile & .DataValueField -- to designate which peices of data it
    should use.

    for ex:

    <people>
    <person id="1" name="Joe">[blah]</person>
    <person id="2" name="Bob">[blah]</person>
    <person id="3" name="Roberto">[blah]</person>
    </people>

    ....you can successfully use this nodelist as a .DataSource, but i
    havent figured out a way to specificy which elements of the data to use
    for what.

    thanks,
    matt
    , Jun 25, 2005
    #3
    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. Kevin

    ASP.Net design flaw!?

    Kevin, Jan 22, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    899
    Kevin
    Jan 27, 2004
  2. nospam

    Annoying flaw / bug in ASP.NET

    nospam, Jun 6, 2005, in forum: ASP .Net
    Replies:
    5
    Views:
    752
    Kevin Spencer
    Jun 6, 2005
  3. Kevin Steffer [MCP]

    Security Flaw in dll (or am I wrong?)

    Kevin Steffer [MCP], Jun 14, 2005, in forum: ASP .Net
    Replies:
    11
    Views:
    582
    Kevin Spencer
    Jun 16, 2005
  4. =?ISO-8859-1?Q?Christian_Engstr=F6m?=

    non-const function return values: gcc bug or language flaw?

    =?ISO-8859-1?Q?Christian_Engstr=F6m?=, Feb 7, 2004, in forum: C++
    Replies:
    19
    Views:
    1,125
    tom_usenet
    Feb 10, 2004
  5. Replies:
    2
    Views:
    276
    Rick Johnson
    Dec 25, 2012
Loading...

Share This Page