0

リストボックスと送信ボタンがあり、クリックするとイベントが発生します。イベントハンドラでは、リストボックスのどの要素が現在選択されているかという情報が必要です。問題は、インデックスが-1になるたびに??

<form id="form1" runat="server">
    <div>

        <asp:ListBox ID="ListBox1" runat="server" Height="400px" Width="200px"></asp:ListBox>

    </div>
        <asp:Button ID="Button1" runat="server" Height="60px" Text="Send"  Width="100px" OnClick="send"/>

    </form>

これは、.aspx ファイル内のコードです。

4

1 に答える 1

0

GetSelectedIndices()メソッドを使用して、選択したインデックスを取得できます。

int[] selectedItemsIndexes = myListbox.GetSelectedIndices();

またはあなたが使用することができます

foreach(Object selecteditem in listBox1.SelectedItems)
{

}
于 2012-11-06T16:27:55.020 に答える