views:

32

answers:

1

Looking for a custom ASP .NET control were the InnerHTML of a DIV is connected to a databas to fetch the content to render the HTML content from the databas inside the DIV.

Is there one out there I have missed or anyone could tell if its possible to make my own DIV component to make it DataBound?

Thanks, Stefan

A: 

You can't databind to a div, but you can databind to something like a Repeater, which is mainly good for showing rows of data (i.e. repeating the same markup for multiple data items).

If you just want to show one field from one row, you're probably better off with something like a literal:

<div>
    <asp:Literal id="myLiteral" runat="server" />
</div>

And then in the code behind...

myLiteral.Text = "some string from the database or wherever";
mgroves
Hi and thanks for your reply. What you wrote is a bit what I wanted to avoid, would had been nice to just have my own visual component for displaying databound HTML content. Maybe I worrie to much about opening and closing an Sql Connection to often. I will go ahead creating a general class of fetching the HTML content from the database and bind it to an literal.cheers
StefanE
You only need to set the Text once when !IsPostback, so you'd only need to open a Sql Connection once. I should also mention that you can do a runat=server div and set the InnerText/InnerHtml if you prefer.
mgroves