Hello,
I am using a webDropDown w/ MultipleSelectionType = Checkbox. Is it possible to access a list of selected values for the list of selected items? I see this question was asked but it was over 7 years ago.
I'm using version 19.1 of the controls.
Hi Stewart,
You can get the collection of selected items from the event arguments in the SelectionChanged event:
protected void WebDropDown1_SelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e) { DropDownItem[] selectedItems = (DropDownItem[])e.NewSelection; }
Please let me know if you have further questions.
>> access a list of selected values
I have the selected items. I want their selected values.
WebDropDown1.Selectedvalue <<< I want the list of values (plural)
As easy as:
protected void WebDropDown1_SelectionChanged(object sender, Infragistics.Web.UI.ListControls.DropDownSelectionChangedEventArgs e) { DropDownItem[] selectedItems = (DropDownItem[])e.NewSelection; var listOfValues = new List<string>();
foreach (DropDownItem item in selectedItems) { listOfValues.Add(item.Value); } }
Great! I'll check that out. Thank-you.
In Visual Studio 2017, as soon as I add a handler for the WebDropDown1.SelectionChanged, my project blows up with 26 errors even with no code in the handler.
Any idea why I would get so many errors?
I am guessing that because your example uses SelectionChanged, I have to build the list each time the selection changes rather than being able to access the entire list at some point during form submission without the use of this handler. I was hoping the control would maintain this on it's own.
Please add
Imports Infragistics.Web.UI.ListControls
so that you resolve the errors.
And you dont have to build the list each time. Actually, the SelectionChanged will fire only once by default, when a postback is triggered by any action (form submission for example). I think this works for your scenario. If, however, you have the SelectionChanged postback flag set to ON:
<ig:WebDropDown ID="WebDropDown1 ...> <AutoPostBackFlags SelectionChanged="On"/>
then the event will fire for every selection. In this case you may build the collection of values at another point, by iterating the this.WebDropDown1.SelectedItems collection.
I had the imports statement present in my code prior to your suggesting I add it.
So why the errors?
Hello Stewart,
Please make sure that your project references the respective assembly files.