Get selected index, text and value from asp:listbox (VB.net)
<%@ Page Language=VB Debug=true %>
<script runat=server>
Sub SubmitBtn_Click(Sender As Object, E As EventArgs)
lblDataSelected.Text = "Selected Text: " _
& lb1.SelectedItem.Text & "<BR>Selected Value: " _
& lb1.SelectedItem.Value & "<BR>Selected Index: " _
& lb1.SelectedIndex
End Sub
</SCRIPT>
<HTML>
<HEAD>
<TITLE>Creating a Basic ListBox Control</TITLE>
</HEAD>
<form runat="server">
<BR><BR>
<asp:label id="lblDataSelected" runat="server"/>
<BR><BR>
<asp:listbox id="lb1" runat="server" rows=3>
<asp:listitem value="Bu">Blue</asp:listitem>
<asp:listitem value="Re">Red</asp:listitem>
<asp:listitem value="Gr">Green</asp:listitem>
<asp:listitem value="Pu" Selected>Purple</asp:listitem>
<asp:listitem value="Ba">Black</asp:listitem>
<asp:listitem value="Go" text="Gold"/>
</asp:listbox>
<BR><BR>
<asp:button id="butOK" text="OK" type="Submit" onclick="SubmitBtn_Click" runat="server"/>
</form>
</BODY>
</HTML>
Related examples in the same category