Checkboxlist control in asp net

Checkboxlist Asp.Net Control:



A checkboxlist is the collection of squared object that allows to you to click on these given item for selection. If the square is empty then it return false, and when you clicked, the square would have a check mark and return true.  And if again you do the square had a check mark (clicked), the check mark would be removed from checkboxlist item checkbox. The each item of checkboxlist (checked or unchecked has Boolean values) holds a Boolean value of true or false. When it is not marked, then it has a value of false and when it is marked, then it has a value of true.

ASP.net How to use Checkboxlist:

Creating checkboxlist on asp.net page. Checkboxlist control enables to use to multi-selection check box in list.

<asp:CheckBoxList ID="chklstStates" runat="server">
            </asp:CheckBoxList>

 This is example code for taking a checkboxlist on asp.net web page.

Create checkboxlist with list item:

<asp:CheckBoxList ID="check1" AutoPostBack="True" TextAlign="Right" runat="server">
            <asp:ListItem>Item 1</asp:ListItem>
            <asp:ListItem>Item 2</asp:ListItem>
            <asp:ListItem>Item 3</asp:ListItem>
            <asp:ListItem>Item 4</asp:ListItem>
            <asp:ListItem>Item 5</asp:ListItem>
            <asp:ListItem>Item 6</asp:ListItem>
        </asp:CheckBoxList> 

Checkboxlist related other old post on asp.net tutorial:

Asp.net c# CheckBoxList control example:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="checkboxlist1aspx.aspx.cs"
    Inherits="checkboxlist1aspx" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title>ASP.net How to use Checkbox list control</title>
    <style type="text/css">    
     div
     {
         margin:10px;
     }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <div>
        <div style="width:400px; float:left;">
        <fieldset>
            <h3>&nbsp;Checkbox list control Example:</h3>
            <p>List of State: select checkbox from this checkboxlist control:</p>
            <div>
            <asp:CheckBoxList ID="chklstStates" runat="server">
                <asp:ListItem Text="Alabama" Value="Alabama"></asp:ListItem>
                <asp:ListItem Text="Alaska" Value="Alaska"></asp:ListItem>
                <asp:ListItem Text="Arizona" Value="Arizona"></asp:ListItem>
                <asp:ListItem Text="Arkansas" Value="Arkansas"></asp:ListItem>
                <asp:ListItem Text="California" Value="California"></asp:ListItem>
                <asp:ListItem Text="Connecticut" Value="Connecticut"></asp:ListItem>
                <asp:ListItem Text="Florida" Value="Florida"></asp:ListItem>
                <asp:ListItem Text="Delaware" Value="Delaware"></asp:ListItem>
                <asp:ListItem Text="Hawaii" Value="Hawaii"></asp:ListItem>
                <asp:ListItem Text="Kentucky" Value="Kentucky"></asp:ListItem>
                <asp:ListItem Text="Maryland" Value="Maryland"></asp:ListItem>
                <asp:ListItem Text="New Jersey" Value="New Jersey"></asp:ListItem>
                <asp:ListItem Text="New York" Value="New York"></asp:ListItem>
            </asp:CheckBoxList>
            </div>
            <asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        </fieldset>
        </div>
        <div style="width:289px; float:left;">
         <fieldset style="width: 297px">
            <h3>Selected States:</h3>
             <p>selected checkbox from this checkboxlist</p>
             <p>&nbsp;</p>
            <div>
                <asp:Label ID="lblStates" runat="server"></asp:Label>
            </div>
        </fieldset>
        </div>
    </div>
    </form>
</body>
</html>
 
how_to_use_checkboxlist_control
how to use checkboxlist control

CheckBoxList Control C# code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class checkboxlist1aspx : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        lblStates.Text = string.Empty;
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        foreach (ListItem item in chklstStates.Items)
        {
            if (item.Selected)
                lblStates.Text += item.Text + "<br>";
        }
    }
}


Other Importent Asp.net Related Post:



Comments

Popular posts from this blog