how to scroll selected item in asp listbox in mult

2020-03-31 06:55发布

问题:

I have a listbox with selection mode is multiple

<asp:ListBox id="Listbox1" runat="server" Width="230px" Height="168px" 
SelectionMode="Multiple"></asp:ListBox>

I am databinding using a datasource

Me.Listbox1.Items.Clear()
Me.Listbox1.DataSource = ayl_arraylist_memberslist
Me.Listbox1.DataTextField = "Key"
Me.Listbox1.DataValueField = "Value"
Me.Listbox1.DataBind()

I am sending one listbox listbox1 item into userlistbox but after pressing add I can't get scrolled to selected item.

回答1:

Better to take html list box

<select id="ListBox1" runat="server" size="10" style="width:230px; height:168px"></select>


<%--<asp:ListBox id="ListBox1" runat="server" Width="230px" Height="174px" SelectionMode="Multiple" ></asp:ListBox>--%>

and using jquery listbox change function in document.ready we can modify at the multiple mode as

$("#ListBox1").attr("multiple", false);
 $("#ListBox1").change(function () { $("#ListBox1").attr("multiple", true); });

and write behind .cs code to get slected index