如何在asp.net中绑定到一个标签时改变字符串的颜色? [英] How to change the colour of a string when binding to a label in asp.net?

查看:112
本文介绍了如何在asp.net中绑定到一个标签时改变字符串的颜色?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在其中用户输入值,并点击一个button.When按钮被点击我要使用第二个框,以取代在第一个框中的值并显示在一个标签。两个文本框

I have 2 text boxes in which the user enters values and clicks a button.When the button is clicked I want to replace the value in the first box with to the second box and show it in a label.

我想在彩色格式,以显示替换值,使得用户可以容易地识别它。

I want to show the replaced value in a colour format so that the user can identify it easily.

那么,怎样才能字符串可以格式化的色彩,我要的颜色字符串不是标签

So how can a string can be colour formatted, I want to colour the string not the label

对于例如:

<asp:Label ID="lblName" runat="server"></asp:Label>
string value1 = "Hi! This is a demo code";
lblName.Text = value1.Replace("demo", "sample");

现在我的标签显示我的嗨!这是一个示例code

Now my label shows me "Hi! This is a sample code"

有我只想样品来进行着色和休息是一样的正常的标签文本是

There I want only the sample to be coloured and rest be same as a normal label text be

推荐答案

一个简单的方法来做到这将是包装在跨度替换文本具有关联样式或CSS类:

A simple way to do it would be to wrap the replacement text in a span with an associated style or css class:

lblName.Text = value1.Replace("demo", "<span style='color: red;'>sample</span>"));

这篇关于如何在asp.net中绑定到一个标签时改变字符串的颜色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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