如何根据指定的文本更改标签的颜色 [英] How to Change the Color of the label based upon the text assigned

查看:80
本文介绍了如何根据指定的文本更改标签的颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Datalist ItemTemplate中有标签。



如何根据显示的文字更改标签的颜色..



我正在使用Eval属性分配文本..这是来自db表..



如果文本是中断然后颜色应该是红色的,否则它应该是绿色的



如何在.aspx页面中实现它plz帮助..



i不想使用绑定的行数据

解决方案

你可以使用datalist的项数据绑定事件来查看标签的文本并根据您的条件申请颜色。



在谷歌上查看项目数据包的更多内容





https://www.google.co.in/#q=datalist%20itemdatabound


尝试设置Label的BackColor或ForeColor属性,例如



 BackColorr ='<%#Convert.ToString(Eval(Fieldname))==Break? red:green%>'

//相应地更改字段名称,颜色和格式



 BackColorr ='<%#Convert.ToString(Eval(Fieldname))==Break? System.Drawing.ColorTranslator.FromHtml(#FDEEEE):System.Drawing.ColorTranslator.FromHtml(#FFFFF)%>'



甚至你可以使用ac#方法并在标记中调用它。



其他替代方法是在RowDataBound事件和FindControl中处理Label控件并设置颜色。


I'm having a Labels in my Datalist ItemTemplate.

How to Change the Color of the label based upon the text displayed..

i'm using Eval Property to assign text.. which was from db table..

if the text is break then color should be red else it should be green

How to Achieve it in .aspx page plz help..

i don't want to use row data bound for it

解决方案

well you can use datalist 's item data bound event to see the text of the lable and apply color based on your condition.

see more on item databound on google


https://www.google.co.in/#q=datalist%20itemdatabound


Try setting the BackColor or ForeColor property of Label like

BackColorr='<%# Convert.ToString(Eval("Fieldname")) == "Break" ? "red" :"green" %>' 

// change the fieldname ,color and also format accordingly
Or

BackColorr='<%# Convert.ToString(Eval("Fieldname")) == "Break" ? System.Drawing.ColorTranslator.FromHtml("#FDEEEE") :System.Drawing.ColorTranslator.FromHtml("#FFFFF") %>'


Or even you can use a c# method and just call it in the Markup .

Other alternative is to handle in the RowDataBound event and FindControl the Label control and set the color.


这篇关于如何根据指定的文本更改标签的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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