如何为标签内的部分文本动态着色 [英] How to dynamically color some part of text inside a label

查看:94
本文介绍了如何为标签内的部分文本动态着色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下面的代码中,我想以红色动态显示变量'v_totalitemsfound'

的颜色。我试图用span但不接受。



totalitemsfound.Text =(在此类别中+ Convert.ToString(v_totalitemsfound)+找到的项目);

In the following code I want to dynamically display the color of the variable 'v_totalitemsfound'
in red. I attempted with span but not accepting.

totalitemsfound.Text = "(in this category " + Convert.ToString(v_totalitemsfound) + " items found)";

推荐答案

请参阅下面的测试代码

See I have tested a code following below
protected void Page_Load(object sender, EventArgs e)
   {
       Label1.Text = "<span style='color:red'>This is testing only</span>";

   }



对于你应该是


And for you that should be

totalitemsfound.Text = "<span style='color:red'>(in this category " + Convert.ToString(v_totalitemsfound) + " items found)</span>";


这篇关于如何为标签内的部分文本动态着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆