开发者

.NET/ASP.NET and placeholders in databases

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 d开发者_StackOverflow社区o so?


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.


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);
    }


Have a look at these:

  1. Place holder in .NET.

  2. Dynamic Loading of ASP.NET User Controls.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜