Check Box List control in asp.net

 For Example: Write a program to demonstrate the use of checkboxlist control

.ASPX code

<html>

<head runat="server">

    <title>Aryan Computers (CheckBoxList) </title>

</head>

<body>

    <form id="form1" runat="server">

    <div>

        <asp:Label ID="Label1" runat="server" Font-Bold="True" Font-Size="X-Large"

            Text="Example of CheckBoxList control: "></asp:Label>

    </div>

    <asp:CheckBoxList ID="CheckBoxList1" runat="server" >

        <asp:ListItem>Core Java</asp:ListItem>

        <asp:ListItem>Data Mining</asp:ListItem>

        <asp:ListItem>ASP.NET</asp:ListItem>

        <asp:ListItem>C++ Pro.</asp:ListItem>

    </asp:CheckBoxList>

    <br />

    <asp:Label ID="Label2" runat="server" Text="Label" Font-Bold="True"

        ForeColor="#009933"></asp:Label>

    <br />

    <br />

    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Check" />

    </form>

</body>

</html>

.ASPX.CS code

namespace WebApplication73

{

    public partial class WebForm7 : System.Web.UI.Page

    {

        protected void Button1_Click(object sender, EventArgs e)

        {

            {

                Label2.Text = "Selected Items are :<br /><br />";

                for (int i = 0; i < CheckBoxList1.Items.Count; i++)

               {

                    if (CheckBoxList1.Items[i].Selected)

                    {

                        Label2.Text += CheckBoxList1.Items[i].Text + "<br />";

                    }


                }

            }

        }

    }

}

 Output:



Comments

Popular posts from this blog

simple program C#

Regular Expression Validator Control in asp.net

two dimension array in C#