javascript - How to Store List of selected value from multiselect dropdown list in array in asp.net? -
i used bootstrap multiselect dropdown item, in if select many values select first values, whats wrong in code logic.
asp dropdown list
<asp:dropdownlist width="320px" id="drplstgetdb" runat="server" multiple="multiple"> </asp:dropdownlist>
javascript enable multiple check feature bootstrap.
$(function() { $('[id*=drplstgetdb]').multiselect({ includeselectalloption: true }); });
c# code store in array.
int[] stopwordarray = new int[drplstgetdb.items.count]; foreach(listitem listitem in drplstgetdb.items) { if (listitem.selected) { int = 0; stopwordarray[i] = convert.toint32(drplstgetdb.items[i].value.tostring()); i++; } }
i getting first checked value in array, if don't use if if (listitem.selected) can store values in array. can suggest error,, specially selected logic. or alternative this..
because setting
int = 0
inside loop, setting first array element of stopwordarray time, no matter what. move the
int = 0
to outside of foreach , should have better luck there.
try this
int[] stopwordarray = new int[drplstgetdb.items.count]; int = 0; foreach(listitem listitem in drplstgetdb.items) { if (listitem.selected) { stopwordarray[i] = convert.toint32(listitem.value.tostring()); //something i++; } }
maybe easier rid of int array , use list
list<int> stopwordarray = new list<int>(); foreach (listitem listitem in drplstgetdb.items) { if (listitem.selected) { stopwordarray.add(convert.toint32(listitem.value.tostring())); } }
Comments
Post a Comment