Saturday, 3 November 2012

Dynamically adding controls to a web page


In order to programmatically add a control to a page, there must be a container for the new control. For example, if you are creating table rows, the container is the table. If there is no obvious control to act as container, you can use a PlaceHolder or Panel Web server control.

In some instances, you might want to create both static text and controls. To create static text, you can use either a Literal or a Label Web server control. You can then add these controls to the container as you would any other control. For information about view state in controls created at run time.
.

take 1 panel control on the web page....

and in the page load event write the code...

                   Label l = new Label();                   l.Text = "Sample Label"
                   Panel P= new Panel();                   P.Controls.Add(l);
by this u can add the controls on the web page....

adding image controls .......

first make the database in which u store the path of images.
then in web page take panel control...
in the class write the code...


in the page load event write code....


if u have 5 images in the database it add 5 image control .and if have 50 images in the database it add 50 image control...

No comments :

Post a Comment