Click here to Skip to main content
16,021,172 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello,

I am developing a project in which i have to insert a list of checkboxes dynamically when the user checks the existing checkbox on the page.
i tried doing this but its not working if user select the existing checkbox i.e chk1

my .cs page
C#
protected void chk1_CheckedChanged(object sender, EventArgs e)
    {
        if (chk1.Checked)
        {
            int a = 1;
            for (; a <= 6; a++)
            {
                CheckBox chklst1 = new CheckBox();
                chklst1.ID = "med_chk" + a;
                panl1.Controls.Add(chklst1);
                Literal li2 = new Literal();
                li2.Text = "";
                panl1.Controls.Add(li2);
            }
        }
    } 

my .aspx page
ASP.NET
<form id="form1"  runat="server">
<asp:Panel ID="panl1" runat="server">
<asp:CheckBox ID="chk1" runat="server" Text="hai" oncheckedchanged="chk1_CheckedChanged">
</form>

please help me.asap.
Posted
Updated 21-May-12 0:03am
v2

Please refer:
How to generate Dynamic Checkbox in ASP.Net using C#[^]

And more imp. make auto post back property True of your check box.
 
Share this answer
 
Comments
shabadiveda 21-May-12 7:34am    
thank you 4 d reply...i tried its working fine
Prasad_Kulkarni 21-May-12 7:35am    
Glad it helps!
You're welcome.
use auto postback =true for existing checkbox
 
Share this answer
 
Comments
shabadiveda 21-May-12 7:34am    
thank you 4 d reply...i tried its working fine
vangapally Naveen Kumar 21-May-12 7:41am    
welcome.........
add AutoPostBack="true" in check box attribute. Like this

C#
<asp:checkbox id="chk1" runat="server" text="hai" oncheckedchanged="chk1_CheckedChanged" autopostback="true" xmlns:asp="#unknown" />
 
Share this answer
 
Comments
shabadiveda 21-May-12 7:34am    
thank you 4 d reply...i tried its working fine

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900