views:

65

answers:

3

I have a web page (ASP.NET, ASCX) which has to show some contents of a database. The choice of contents is determined by some variable, say x. So, if x=1, I show the first column of a given database table, if x=2 I show the second column and so on.

I am told that I need to use a thing called "placeholder".

Can anyone show me how to do so?

A: 

Have a look at these:

  1. Place holder in .NET.

  2. Dynamic Loading of ASP.NET User Controls.

Pandiya Chendur
Thanks!!! Reading...
Giuseppe
A: 

A placeholder is essentially just a "container" for content - where your content will go when you actually know what you want to show. There are several ways to implement this in ASP.NET and the choice of control depends on the nature of the content.

If your DB contains HTML, you could use a Literal control to display it. If it's text and you want to apply a style to it, you can use a Label control. There is also a PlaceHolder control which is used when you want to dynamically (from code-behind) add child controls to a part of a page.

Anders Fjeldstad
Thanks! That's on the spot! Now I would need a couple of examples...
Giuseppe
You could always start by checking out the API documentation for each of the controls - I have added links to the respective control names in my response.
Anders Fjeldstad
A: 

If you want code to add a user control to a place holder then do the following.

In your web form add:

    <%@ Reference Control = "WebUserControl1.ascx" %>

    if (!Page.IsPostBack)
    {
        WebUserControl1 uc =
          (WebUserControl1) Page.LoadControl("WebUserControl1.ascx");
        PlaceHolder1.Controls.Add(uc);
    }
Pandiya Chendur