Since I have a field, which contain html content, in dataset returned from database. I want to sue a div to display the html content by using
div.inner开发者_运维百科Html=...
I can find div control in Repeater1_ItemDataBound event but don't know how to bind that field to the control. That field is called 'actualContent'. I think write
div.innerHtml=<%=actualContent%> won't work in backend
Then how to bind that field? Thank you in advance.
Add runat="server" to the div, and put your content in between the tagsm like this:
ASPX
Literal method:
<div ID="div1" runat="server">
<%#Eval("ActualContent")%>
</div>
DIV method:
<div ID="div1">
<asp:Literal ID="Literal1" runat="server" Text='<%#Eval("ActualContent")%>' />
</asp:Panel>
Code behind
Literal method:
string literalValue = ((Literal)e.Item.FindControl("Literal1")).Text;
DIV method:
string divValue = ((HtmlGenericControl)e.Item.FindControl("div1")).InnerHtml;
Couple of things:
- Make sure the div is marked with runat="server"
on ItemData_Bound, find the div and simply do:
div.innerHTML=Item.actualContent;
That should do it, I think.
hi there is two way for this,
1) set div InnerHtml property from .cs file like.
div1.InnerHtml = "This data will be bind.";
2) if you want fill it from datasource so simply use Eval tag in aspx page like
<div ID="div1" runat="server">
<%#Eval("YourColumName")%>
</div>
精彩评论