Listbox Item Selection
-
Hi, How does one check if an item in a listbox is selected? Usually I would do it like this if I have multiple items selected: foreach (ListItem item in lbFacilities.Items) { if (item.Selected) ...code here... } Is the best way like this (even if the SelectionMode property is not set to Multiple? Or would the following also be appropriate? if (lbWineries.SelectedValue == string.Empty) ...code here... Regards, ma se
-
Hi, How does one check if an item in a listbox is selected? Usually I would do it like this if I have multiple items selected: foreach (ListItem item in lbFacilities.Items) { if (item.Selected) ...code here... } Is the best way like this (even if the SelectionMode property is not set to Multiple? Or would the following also be appropriate? if (lbWineries.SelectedValue == string.Empty) ...code here... Regards, ma se
I think the best way to check for selected items is to use SelectedIndex if the selection mode property is One or SelectedIndices if its multiple. Regards, Wasif Ehsan.
-
I think the best way to check for selected items is to use SelectedIndex if the selection mode property is One or SelectedIndices if its multiple. Regards, Wasif Ehsan.
Thanks for the reply. You mean like (for single selection): if (lbWineries.SelectedIndex == 0) Is this right?
-
Hi, How does one check if an item in a listbox is selected? Usually I would do it like this if I have multiple items selected: foreach (ListItem item in lbFacilities.Items) { if (item.Selected) ...code here... } Is the best way like this (even if the SelectionMode property is not set to Multiple? Or would the following also be appropriate? if (lbWineries.SelectedValue == string.Empty) ...code here... Regards, ma se
-
for (int i =0;i<=lbFacilities.Items.Count -1;i++) { if (lbFacilities.Items[i].Selected ==true) ...code here... }
Is this the correct way to check if a single item is selected? Even if the selectionmode is not set to multiple?