Click here to Skip to main content
15,911,360 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi All,

i had created a dynamic check boxes for my project. but not sure how to create click event for these check box, please can any one help me in resolving this issue.

below is my code which i had written so far:
C#
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlcon"].ConnectionString);
con.Open();

string query = "select * from state";
SqlCommand cmd = new SqlCommand(query, con);
dv = cmd.ExecuteReader();

while (dv.Read())
{
    CheckBox list = new CheckBox();
    list.ID = dv[0].ToString();
    list.Text = dv[0].ToString();
    Panel1.Controls.Add(new Label { Text=""});
    Panel1.Controls.Add(list);
}

con.Close();
Posted
v2
Comments
Mahesh Bailwal 30-May-13 1:55am    
JavaScript event or server side event?
jonlink01 30-May-13 2:01am    
its for server side event

1 solution

Hi,

we can create event dynamically also.please Add the CheckedChnaged event as defined below
C#
list.CheckedChanged += new EventHandler(chk_CheckedChanged);


Define what you need to do in the checked change event as below.
C#
void chk_CheckedChanged(object sender, EventArgs e)
{
    throw new NotImplementedException();
}


Regards,
Kiran.
 
Share this answer
 
v2
Comments
jonlink01 30-May-13 3:17am    
Hi Kiran,

Thank you for your help. I have a string variable A, i would like to include text property of all the checkbox in string variable A.

can i do that

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