Possible Bug in Lisbox.Databinding for collections

M

Miguel Navarro

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
 
G

Guest

Ok, never mind if I set the DataKeyField to "Key"
and DataValueField to "Value" it works fine.
 
L

Lostinet.Web Support

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"));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top