c# - Cannot select multiple items in Listbox -


i have listbox , dropdownlist in gridview edititemtemplate. on rowediting, want select items in listbox. below code:

string categories = (e.row.findcontrol("lblcategoryid") label).text;           listbox lbx = (listbox)e.row.findcontrol("lbselectedcategory"); dropdownlist drp = (dropdownlist)e.row.findcontrol("drpcat"); list<string> tagids = categories.split(',').tolist(); lbx.selectionmode = listselectionmode.multiple; foreach (string s in tagids) {      listitem li = drp.items.findbyvalue(s);      lbx.items.add(li); } 

here items gets added listbox.

but when try select multiple items,

for (int = 0; < lbx.items.count; i++) {      lbx.items[i].selected = true; } 

i error :

cannot select multiple items in dropdownlist.

aspx:

<edititemtemplate>    <asp:label id="lblcategoryid" text='<%# bind("tag_id") %>' runat="server"></asp:label>    <asp:listbox id="lbselectedcategory" visible="false" width="150px" runat="server"          selectionmode="multiple" cssclass="chosen-select"></asp:listbox>    <asp:dropdownlist id="drpcat" autopostback="true"          onselectedindexchanged="drpcat_selectedindexchanged" cssclass="chosen-select" runat="server">    </asp:dropdownlist> </edititemtemplate> 

can me solving issue?

instead of finding rows in drop down , adding same rows listbox, try creating new listitem same value listitem drop down , add instead.


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -