How to highlight or change the color of some words

2020-02-26 11:13发布

I have a label containing some text and I want to highlight or change the color of some words in the text of the label and not all of the words. It has to be dynamic. Any suggestions?

It's for c# with ASP.NET in a user control in webpart in sharepoint

标签: c# .net asp.net
7条回答
\"骚年 ilove
2楼-- · 2020-02-26 11:55

You could use a Substitution control if caching is a concern.

<asp:Label ID="Label1" runat="server" Text="">
    <asp:Substitution ID="Substitution1" runat="server" MethodName="GetDynamicLabel"/>
</asp:Label>

protected static string GetDynamicLabel( HttpContext context )
{
    return string.Format( "<span style='background-color:Blue;'>{0}</span> {1}", "Blue", "Not Blue" );
}
查看更多
登录 后发表回答