Dynamically load asp.net Content from database

751 views Asked by At

My solution consists out of a single page, "Content.aspx" which I use to populate with different types of html data depending on the querystring.

I need to know, if possible, how to load aspx content in my page. I've tried adding code like :

<asp:Label ID="lblName" runat="server"></asp:Label>

But it gets displayed as plain text. Here is my code that I use to retrieve the data from the database.

string category = Request.QueryString["category"].ToString();
using (MyEntity dbc = new MyEntity())
{
    ContentTables cms = (from c in dbc.ContentTable
                         where c.Name == category && c.Status == true
                         select c).First();
    divHeader.InnerHtml = cms.Header;
    divContent.InnerHtml = cms.Content;
    if (cms.Header == "dataPage")
    {
       /*Code Requirement Here*/
    }
}

Any help will be greatly appreciated. Thanks

1

There are 1 answers

0
4b0 On

Use StringBuilder and Literal

StringBuilder sb = new StringBuilder();
sb.append("Your Contain From Database");
Literal1.Text = sb.ToString(); //Bind Contain to Litral

The StringBuilder AppendFormat method is useful for generating text based on a pattern.