asp.net的listbox只有value和text,,没有index。
比如: <div>
            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem Text="1" Value="1" />
                <asp:ListItem Text="2" Value="2" />
                <asp:ListItem Text="3" Value="3" />
            </asp:ListBox>
            <asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
        </div>
 string content = ListBox1.Items.OfType<ListItem>().FirstOrDefault(x => x.Text == "3").Value;
            ClientScript.RegisterClientScriptBlock(this.GetType(), "", "<script>alert('" + content + "');</script>");
就可以通过页面显示的值获得实际的value。

解决方案 »

  1.   

    我记得在delphi中就有indexof方法,ASP.NET中没有类似的方法吗?
      

  2.   

            <asp:ListBox ID="ListBox1" runat="server">
                <asp:ListItem Text="1" Value="1" />
                <asp:ListItem Text="2" Value="2" />
                <asp:ListItem Text="3" Value="3" />
            </asp:ListBox>                ListBox1.Text = "3";
                    Response.Write(ListBox1.SelectedIndex);
                    Response.End();