programming we consider all important topic for knowledge about controls,web Services, JSON, Ajax, database, and interview related Question. In this and sql server tutorial blog we give many examples of jquery as like How Play YouTube Video in Your Website by URL, How to Play YouTube Videos in by using Jquery , Jquery Change div background on mouseover in , JQuery UI Datepicker (Calendar) etc.

Monday, August 25, 2014

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. How to use Checkboxlist:

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

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

 This is example code for taking a checkboxlist on 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>

Checkboxlist related other old post on tutorial: 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" "">
<html xmlns="">
<head id="Head1" runat="server">
    <title> How to use Checkbox list control</title>
    <style type="text/css">    
    <form id="form1" runat="server">
        <div style="width:400px; float:left;">
            <h3>&nbsp;Checkbox list control Example:</h3>
            <p>List of State: select checkbox from this checkboxlist control:</p>
            <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:Button ID="btnSubmit" runat="server" Text="Submit" OnClick="btnSubmit_Click" />
        <div style="width:289px; float:left;">
         <fieldset style="width: 297px">
            <h3>Selected States:</h3>
             <p>selected checkbox from this checkboxlist</p>
                <asp:Label ID="lblStates" runat="server"></asp:Label>
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 Related Post:

No comments:

Post a Comment