Mega Code Archive

 
Categories / ASP.Net Tutorial / ASP Net Controls
 

Get selected item index from asp

<%@ Page Language="VB" %> <script runat="server">    sub Submit(Sender as Object, e as EventArgs)       dim strIncome as string = lbIncome.SelectedItem.Text       dim strAge as string = rlAge.SelectedItem.Text              lblMessage.Text = "Hello " & tbName.Text & "!" & _          "Your income is: " & strIncome & "<br>" & _          "Your age is: " & strAge & "<br>"              if rlAge.SelectedIndex < 3 then          lblMessage.Text += "You're a young one!"       else          lblMessage.Text += "You're a wise one!"       end if              if cbNewsletter.Checked then          lblMessage.Text += "You will be receiving our" & _             " newsletter shortly."       end if    end sub    </script> <html><body>    <form runat="server">       <asp:Label id="lblMessage" runat="server" />              Enter your name:        <asp:TextBox id="tbName" runat="server" />              Choose your age:<br>       <asp:RadioButtonList id="rlAge" runat="server"          RepeatDirection="horizontal">          <asp:ListItem><18</asp:ListItem>          <asp:ListItem>19-24</asp:ListItem>          <asp:ListItem>25-34</asp:ListItem>          <asp:ListItem>35-49</asp:ListItem>          <asp:ListItem>50-65</asp:ListItem>       </asp:RadioButtonList>              Choose your income:<br>       <asp:ListBox id="lbIncome" runat="server"          size=1>          <asp:ListItem>< $9</asp:ListItem>          <asp:ListItem>$10-$99</asp:ListItem>          <asp:ListItem>$100-$499</asp:ListItem>          <asp:ListItem>> $500</asp:ListItem>       </asp:ListBox>             Do you want to receive our newsletter?<br>       <asp:Checkbox id="cbNewsletter" runat="server"          Text="Yes!" />              <asp:Button id="btSubmit" runat="server"          Text="Submit" OnClick="Submit" />    </form> </body></html>