Get selected value from asp:checkboxlist (VB.net) : CheckBoxList « Asp Control « ASP.Net






Get selected value from asp:checkboxlist (VB.net)

<script runat="server" language="vb">
  Sub Page_Load()
    Dim msg As String = "You have selected the following items:<br />"

    If check1.Items(0).Selected Then msg = msg & check1.Items(0).Text & "<br />"
    If check1.Items(1).Selected Then msg = msg & check1.Items(1).Text & "<br />"
    If check1.Items(2).Selected Then msg = msg & check1.Items(2).Text & "<br />"

    Message.Text = msg
  End Sub
</script>
<html>
  <head>
    <title>Check Box List Example</title>
  </head>
  <body>
    <asp:label id="Message" runat="server" />
    <br /><br />
    Which city do you wish to look at hotels for?
    <br /><br />
    <form runat="server">
    <asp:checkboxlist id="check1" runat="server">
      <asp:listitem id="option1" runat="server" value="Madrid" />
      <asp:listitem id="option2" runat="server" value="Oslo" />
      <asp:listitem id="option3" runat="server" value="Lisbon" />
    </asp:checkboxlist>
      <br /><br />
      <input type="Submit">
    </form>
  </body>
</html>

           
       








Related examples in the same category

1.Loop through asp:checkboxlist (VB.net)
2.Set asp:CheckBoxList Repeat Direction (VB.net)
3.Define and use asp checkboxlist in code behind (C#)
4.Get selected item from asp:checkboxlist (C#)