Question Details

Browse

Need help regarding checkbox

By Jibi - Jun. 21, 2008

I want to create dynamically checkbox and also want to access its checked property when it is clicked in asp.net.


Answers

Add Answer
  1. By osfiend on Jun. 21, 2008

    Following code will explain how to create the dynamic checkboxes.


    Source Code:


    //Drag and drop panal on the Webpage.


    //After drag and drop following code will be generated automatically


    protected System.Web.UI.WebControls.Panel PnlControl;


    //Declare a CheckBox


    CheckBox chkList1;


    private void Page_Load(object sender, System.EventArgs e)


    {


    .


    .


    //Page load code goes here


    .


    .


    }


    #region dyanamic checkboxes


    //Function to generate the dyanamic checkboxes


    private void AddCheckboxes(string strCheckboxText)


    {


    try


    {


    if(PnlTimeExpence.HasControls())


    {


    return;


    }


    for(int intControlIndex=0;intControlIndex=5;intControlIndex++)


    {


    chkList1 =new CheckBox();


    chkList1.Text = strCheckboxText;


    chkList1.ID="Chk"+intControlIndex;


    chkList1.Font.Name = "Verdana";


    chkList1.Font.Size = 9;


    PnlControl.Controls.Add(chkList1);


    PnlControl.Controls.Add(new LiteralControl(""));


    }


    }


    catch(Exception exp)


    {


    throw new Exception(exp.Message);


    }


    }


    #endregion


    0 Votes
  2. By an anonymous user on Jun. 21, 2008

    Here's a great post that should answer your questions: http://devsushi.com/2006/08/27/aspnet-dynamic-control-creation-part-1/


    0 Votes
Share your knowledge

Related Questions

Browse Get answers and share your expertise.