Create CheckBox Dynamically in ASP.NET

how to create checkbox dynamically in

Hello Friends,
In these Tutorials we see how to create checkbox dynamically when we click button its check textbox to display number of CheckBox's.

The below code will help you to Create Dynamically CheckBox in

HTML Markup : Create Page

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Create-Dynamic-Checkbox-RadioButton.aspx.cs" Inherits="Example_Create_Dynamic_Checkbox_RadioButton" %>

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

<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <asp:CheckBox ID="CheckBox1" runat="server" Text="Create CheckBox" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br /><br />
    How Many CheckBox|RadioButton Wants to Create : <asp:TextBox ID="txt" runat="server"></asp:TextBox>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:Button ID="Button1" runat="server" Text="Create Controll" 
            onclick="Button1_Click" /><br /><br /><br />
            <asp:panel ID="Panel1" runat="server"></asp:panel>


C# : Code for Create CheckBox Dynamically

protected void Button1_Click(object sender, EventArgs e)
 if (CheckBox1.Checked && txt.Text!="")
            int count = Convert.ToInt32(txt.Text);
            for (int i = 0; i < count; i++)
                CheckBox chk = new System.Web.UI.WebControls.CheckBox();
                chk.ID = "chk" + i;
                chk.Text = "CheckBox" + (i+1) + "
"; Panel1.Controls.Add(chk); } } }

Post a Comment