How to set innerHTML of an asp Label control

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • moondaddy

    How to set innerHTML of an asp Label control

    I want to use a asp Label control (or a <div runat=server> element) in a
    template column of a datagrid. In the code behind in the grid's
    ItemDataBound event I need to dynamically set the innerHTML of this control
    with data and line breaks (<br>).

    The problem is that while working in the code behind, I don't see any
    properties for this control where I can set innerHTML, only text.

    Any good ideas?

    --
    moondaddy@nospa m.com


  • Steven Cheng[MSFT]

    #2
    RE: How to set innerHTML of an asp Label control

    Hi Moondaddy,

    As for the problem how to set the innerHTML of a ASP Label Control. I think
    you can directly use its "Text" property. For example:

    if we have a Label control as below:
    <asp:Label id="lblHtml" runat="server"> </asp:Label>

    Then in code behind, we can set its innerHtml like this:
    lblHtml.Text = "<table width='200'
    border='1'><tr> <td>content</td></tr></table>";

    So the only thing we need to do is just retrieve the certain Label Control
    from the certain cell in the DataGrid in
    its ItemDataBound event and then use its "Text" property to set the
    innerHtml. Please have a try to see whether this helps. Thanks.


    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)

    Get Preview at ASP.NET whidbey
    Build web apps and services that run on Windows, Linux, and macOS using C#, HTML, CSS, and JavaScript. Get started for free on Windows, Linux, or macOS.


    Comment

    Working...