Get selected CheckBox : CheckBox « ASP.net Controls « ASP.NET Tutorial






<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="CheckBox" %>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        What are your favorite ice cream flavors?<br />
        <br />
        <asp:CheckBox ID="A" runat="server" Text="A" /><br />
        <br />
        <asp:CheckBox ID="B" runat="server" Text="B" /><br />
        <br />
        <asp:CheckBox ID="C" runat="server" Text="C" /><br />
        <br />
        <asp:Button ID="btnSubmit" runat="server" Text="Click Me" /><br />
        <br />
        <asp:Label ID="results" runat="server"></asp:Label></div>
    </form>
</body>
</html>


File: Default.aspx.vb

Partial Class CheckBox
    Inherits System.Web.UI.Page

    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSubmit.Click
        results.Text = ""

        If A.Checked Then
            results.Text &= "A."
        End If

        If B.Checked Then
            results.Text &= "B."
        End If

        If C.Checked Then
            results.Text &= "C."
        End If

    End Sub
End Class








3.11.CheckBox
3.11.1.Import properties, events and methods of CheckBox control
3.11.2.Get selected CheckBox
3.11.3.asp: CheckBox changed event (C#)
3.11.4.use the AutoPostBack property to post the form to the server automatically when the check box is checked or unchecked.