Possible Bug in Lisbox.Databinding for collections

Discussion in 'ASP .Net Web Controls' started by Miguel Navarro, Dec 5, 2003.

  1. When Checking values for listbox.Items for any given
    element it only contains the text, not the value. This
    works properly for datasets, but it seems that Databinding
    method when evaluating listitems is using a method which
    ignores value.


    It could be that I am totally misinterpreting how this
    should work:


    If I create a ListItemCollection of ListItems

    ListItemCollection lic=new ListItemCollection;
    ListItem li=new ListItem;

    li.Value="1";
    li.Text="Some Text";

    lic.Add(li);

    listbox.Datasource= lic;
    listbox.Databind();

    when looking in the collection

    lic.FindByValue("1").Value will return "1"

    however in the listbox

    the lisbox contains only the text and this will return an
    error.

    listbox.Items[0].FindByValue("1").Value


    Thank,
    Miguel
    Miguel Navarro, Dec 5, 2003
    #1
    1. Advertising

  2. Miguel Navarro

    Guest Guest

    Ok, never mind if I set the DataKeyField to "Key"
    and DataValueField to "Value" it works fine.
    Guest, Dec 5, 2003
    #2
    1. Advertising

  3. DataBind() will do Items.Clear() first !!!
    so
    list.DataSource=lic;
    list.DataTextField="Text";
    list.DataValueField="Value";
    list.DataBind();
    list.Items.Insert(0,new ListItem("First Item","1st"));

    "Miguel Navarro" <> ????
    news:00a101c3bb5c$d3ec9b30$...
    > When Checking values for listbox.Items for any given
    > element it only contains the text, not the value. This
    > works properly for datasets, but it seems that Databinding
    > method when evaluating listitems is using a method which
    > ignores value.
    >
    >
    > It could be that I am totally misinterpreting how this
    > should work:
    >
    >
    > If I create a ListItemCollection of ListItems
    >
    > ListItemCollection lic=new ListItemCollection;
    > ListItem li=new ListItem;
    >
    > li.Value="1";
    > li.Text="Some Text";
    >
    > lic.Add(li);
    >
    > listbox.Datasource= lic;
    > listbox.Databind();
    >
    > when looking in the collection
    >
    > lic.FindByValue("1").Value will return "1"
    >
    > however in the listbox
    >
    > the lisbox contains only the text and this will return an
    > error.
    >
    > listbox.Items[0].FindByValue("1").Value
    >
    >
    > Thank,
    > Miguel
    >
    >
    >
    Lostinet.Web Support, Dec 8, 2003
    #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. Doug Poland
    Replies:
    9
    Views:
    728
    VisionSet
    Sep 27, 2003
  2. jobs
    Replies:
    0
    Views:
    1,618
  3. mutex
    Replies:
    0
    Views:
    210
    mutex
    Jul 27, 2003
  4. Rob Miles

    Databinding to custom collections

    Rob Miles, Nov 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    136
    Rob Miles
    Nov 12, 2004
  5. Michal Rezler

    LisBox.SelectedItem always returns 0

    Michal Rezler, Oct 8, 2003, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    150
    Victor Garcia Aprea [MVP]
    Oct 20, 2003
Loading...

Share This Page