Here I will explain how to generate the controls dynamically in code behind using asp.net
Description:
Hi here I will explain how to generate the controls dynamically in asp.net code behind
First design the your aspx page with one panel like this
<html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> </head> <body> <form id="form2" runat="server"> <div> <asp:Panel ID="Panel1" runat="server"> </asp:Panel> </div> </form> </body> </html> |
After that write the following code in page load method like this
protected void Page_Load(object sender, EventArgs e) { Table tbldynamic = new Table(); for (int i = 0; i < 5; i++) { TableCell tc = new TableCell(); TableRow tr = new TableRow(); CheckBox _checkbox = new CheckBox(); _checkbox.ID = "chkDynamicCheckBox" + i; _checkbox.Text = "Checkbox" + i; tc.Controls.Add(_checkbox); tr.Cells.Add(tc); tbldynamic.Rows.Add(tr); } Panel1.Controls.Add(tbldynamic); } |
Now run application you will see dynamically generated checkboxes like that we can generate controls dynamically.
If you enjoyed this post, please support the blog below. It's FREE! Get the latest Asp.net, C#.net, VB.NET, jQuery, Plugins & Code Snippets for FREE by subscribing to our Facebook, Twitter, RSS feed, or by email. |
|||
|
|||
18 comments :
nice and excellent articles
Hi,
How to write "CheckedChanged" Event for each CheckBox.
can u explain how to work with events of dynamically created controls like managing ControlId,events of dynamic control
Suresh Please reply to the above comments 2 and 3.
Hope this works!!!!! :)
Button btnDyn = new Button();
btnDyn.ID = "btnDyn";
btnDyn.Style["Position"] = "Absolute";
btnDyn.Style["Top"] = "100px"; btnDyn.Style["Left"] = "10px";
btnDyn.Click += new EventHandler(Button_Click);
this.form1.Controls.Add(btnDyn);
nice site and excellent tutorials...
But How to find that checkbox ////
when we going to click a button to get value of selected check boxes
Thanx for good guidence.....
hi suresh you are rock man.
can you help me to make a project like book a seat
where i create dynamic seats(img btn)
and make event on all of it
I am not able to Print the dynamic table ....
plz help me
regards
sanjay
dynamic table with label and textboxs
plz help me
I have created one dynamic table .and this table contains Button in each row.I want to access value from each cell on button click event ..How can i do plz give me explain..
what about radiobuttons list
hi thank you for your helpful Article
i have a problem with this
when i want to add text and control in one tablecell just return me one of them
what should i do?
Hi Suresh, you are rock, your code will help us in many critical situation.
Thanks a lot.
Superb and Simple implementation........
Hello,
its good article...but how to retrieve the same dunamically created html controls values in a button click.
Hello dear
i have to create drag and dropable control in asp.net like visual studio online i can drag my panel please tell me some idea about them..
Note: Only a member of this blog may post a comment.