Read RadioButton selection (C#) : RadioButton « Asp Control « ASP.Net






Read RadioButton selection (C#)

<%@ Page Language="c#" %>
<script runat="server">

    void Page_Load()
    {
      string msg = "You have selected the following items:<br />";
      if (chkCities.Items[0].Selected) 
          msg += chkCities.Items[0].Text + "<br />";
      if (chkCities.Items[1].Selected) 
          msg += chkCities.Items[1].Text + "<br />";
      if (chkCities.Items[2].Selected) 
          msg += chkCities.Items[2].Text + "<br />";
          
      lblCities.Text = msg;
    }

</script>
<html>
<head>
    <title>Check Box List Example</title>
</head>
<body>
    <asp:Label id="lblCities" runat="server"></asp:Label>
    <br />
    <br />
    Which city do you wish to look at hotels for?<br />
    <br />
    <form runat="server">
        <asp:checkboxlist id="chkCities" runat="server">
            <asp:listitem id="optMadrid" runat="server" value="Madrid" />
            <asp:listitem id="optOslo" runat="server" value="Oslo" />
            <asp:listitem id="optLisbon" runat="server" value="Lisbon" />
        </asp:checkboxlist>
        <br />
        <br />
        <input type="submit" value="Submit Query" />
    </form>
</body>
</html>

           
       








Related examples in the same category

1.On asp:radiobutton selection state changed (VB.net)
2.asp:radiobutton: group name (VB.net)
3.asp:radiobutton: text align (VB.net)
4.Set asp:radiobutton checked (VB.net)
5.Font-Size, Font-Bold, Font-Name for radio button (VB.net)
6.GroupName for asp:radiobutton (VB.net)
7.Check a asp:radiobutton (VB.net)
8.Radio button auto post back (C#)
9.Watch TextBox, CheckBox and radiobutton auto post back action (C#)
10.Use 'Switch' to read Radio Button Choice (C#)
11.Get selected RadioButton (C#)