ListBox Programaticly Set Multiple Items as Selected

J

Jason L Lind

Hi, I have an ASP.NET 2.0 ListBox control which, due to the compex underlying
data and the fact that it inside a dynamically generated grid, I need to
manually data bind multiple items as selected to.

The following code is how I'd think you'd do it, but it does not work:
foreach (FieldData data in dicData[new KeyValuePair(this.m_strPrototypeId,
this.m_objField.FieldId)])
{

lstBox.Items[lstBox.Items.IndexOf(lstBox.Items.FindByValue(data.Value))].Selected = true;
}

This code does not result in any of the items being selected on render, even
though they are on my control. I've used similar code with .SelectedIndex on
a DropDown list and those bind fine....

Any ideas?

Thank you,

Jason Lind
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,576
Members
45,054
Latest member
LucyCarper

Latest Threads

Top