Monday, September 27, 2010

CheckBoxList Control In ASP.NET

Getting CheckBoxList Selected Item Values into Text Box:

ASPX File Code:

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">

<html xmlns="">
<head runat="server">
    <title>Untitled Page</title>
    <form id="form1" runat="server">
    <asp:CheckBoxList ID="CheckBoxList1" runat="server" AutoPostBack="True"
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

.CS Code:

We want to write code in CheckBoxList1_SelectedIndexChange Event

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
        TextBox1.Text = string.Empty;

        foreach (ListItem listitem in CheckBoxList1.Items)
            if (listitem.Selected)
                TextBox1.Text += listitem.Text + ",";


Get the output for above discussed code from the following link:

                                            CheckBoxList Control Selected Items


  1. This comment has been removed by the author.

  2. Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru ASP.NET Essential Training Online . Nowadays Dot Net has tons of job opportunities on various vertical industry.
    or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.