Click to See Complete Forum and Search --> : How to add controls dynamically to a web form
hitai
February 7th, 2006, 12:06 AM
As my title said, I can`t seem to think of way to do this. B4 this, I`ve been only building windows application. For stand alone applications i know how to do it. But for web applications, it was not a easy as i`ve thought as simply adding new control objects to the form. Can anyone give me some pointers?
ITGURU
February 7th, 2006, 01:25 AM
Dear hitai,
To achieve this functionality follow following step:
1. Add a empty server side table in your Web Page.
2. Follow following step in your Code:
A. Clear your Table in which you want to add control dynamically.
B. Create a instance of TableRow like below example:
TableRow trSearchRow = new TableRow();
C. Create as many instance of TableCell's the controls you want in your a row like below example:
TableCell tcLabel = new TableCell();
D. Now create a instance of your control and set it properties like below example:
Label lblFieldCaption = new Label();
lblFieldCaption.ID = "LabelID";
lblFieldCaption.Text = "LabelCaption";
E. Now add your control into Table Cell like below example:
tcLabel.Controls.Add(lblFieldCaption);
F. Now add your Cell into Table Row like below example:
trSearchRow.Cells.Add(tcLabel);
G. Now add your Table row into Table like below example:
tblSearch.Rows.Add(trSearchRow);
Repeat step B to G till you add all your control.
Hope this will help you out in getting your functionality.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.