ListBox Items

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

I have a generalized Stored Procedure to get the listbox items in a
datareader.Then i am binding the datareader to the listbox. For different
pages and different conditions i need to hide and show some the items
returned by the datareader.

Can anyone help me out to solve this issue.

Thanks in adavnce.
Baren
 
You can change the query to return the correct items on each page. If that's
not possible then you can loop through the Items collection and remove the
ones that should not be there.

foreach (ListItem item in listbox.Items)
{
if (item should not be there)
{
listbox.Items.Remove(item);
}
}
 
Well you could use a dataset in place of a datareader and then use a
dataview based on the dataset to filter/sort the data based on
page/condition then re-bind the listbox.
 
Hi! Thach,

I am developing the site with codebehind as VB.NET.
i wrote the following code, but its givine one error
"Collection was modified; enumeration operation may not execute."

Dim item As ListItem
For Each item In selCategory.Items
If (item.Text = "System Alert") Or (item.Text =
"Underwriting Referral") Or (item.Text = "Inspection requested") Then
selCategory.Items.Remove(item)
End If
Next item

Can you help me??

Regards,
Baren
 
Back
Top