Problem with binding DropDownList with ListItemCollection

G

Guest

Hi

There is a ListItemCollection containing ListItems (of course), each of whose Value and Text properties have been set. The Value and Text's values are different

i.e.
ListItem[0].Text = "Name0"
ListItem[0].Value = "ID0"

ListItem[1].Text = "Name1"
ListItem[1].Value = "ID1"

The above ListItem(s) are a part of the ListItemCollection that I mentioned before

Then I set the DataSource of a DropDownList (on my page) to the ListItemCollection and bind it

DropDownList.DataSource = ListItemCollection
DropDownList.DataBind()

But the DropDownList does not pick up the Value and the Text properties separately. It sets the Text Property of each ListItem as the Value also

On the other hand if I iterate through the ListItemCollection and Add() each ListItem to the DropDownList, then the Value and Text fields are picked separately

i.e.

foreach(ListItem in ListItemCollection

DropDownLIst.Items.Add(ListItem)


Can someone tell me why this is happening and if this is some sort of known issue in .NET

RAMADU
 

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,763
Messages
2,569,562
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top