提交后,在列表框中获取所选值的值

时间:2012-11-06 16:21:19

标签: c# webforms listbox submit

我有一个列表框和一个提交按钮,单击时会触发一个事件。在事件处理程序中,我需要现在选择列表框中哪个元素的信息。问题是每次索引是-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文件中的代码。

1 个答案:

答案 0 :(得分:0)

您可以使用GetSelectedIndices()方法获取所选索引。

int[] selectedItemsIndexes = myListbox.GetSelectedIndices();

或者您可以使用

foreach(Object selecteditem in listBox1.SelectedItems)
{

}
相关问题