Search code examples
c#sqlasp.netsql-serverinfopath

How to take a Sql column value and translate the html into a asp label


Sql column value (generated from a InfoPath RTF control):

<strong xmlns="http://www.w3.org/1999/xhtml"><font color="#7030a0">This</font></strong> is a <font xmlns="http://www.w3.org/1999/xhtml" color="#ff0000"><strong>richtextfield</strong></font>

I have a label in asp.net:

<asp:Label ID="lblOne" runat="server" Text=""></asp:Label>

How can I translate the column value to display the output in the asp label.

Example:

The asp label above would display: `this (in bold and in color) is a richtextfield(in bold and in color)`

Solution

  • You'd probably be better served with a Literal value since you're using raw HTML.

    https://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.literal.mode(v=vs.110).aspx

    <asp:Literal ID="Literal1" runat="server" Mode="PassThrough"></asp:Literal>
    

    In the code-behind

    Literal1.Text = yourSQLValue;
    

    You should consider not placing HTML directly into your page however.