简体   繁体   English

如何检查是否设置了样式属性?

[英]How to check if a style property is set or not?

I can set a label in code behind to be underlined我可以在后面的代码中设置一个带下划线的标签

Label1.Style.Add("text-decoration", "underline");

But how can I check if a Label is underlined or not?但是如何检查标签是否有下划线? Something like this?像这样的东西?

if(Label1.Style.Add("text-decoration") == "underline")
if(Label1.Style[HtmlTextWriterStyle.TextDecoration] == "underline")

Both do not work!两者都不起作用!

If you need to test a certain style and your using web forms I recommend checking the data attribute of that specific style.如果您需要测试某种样式并使用 Web 表单,我建议您检查该特定样式的数据属性。 D Stanley above gave the following code snippet that would work to check for a Boolean value.上面的 D Stanley 给出了以下代码片段,可用于检查布尔值。

Label1.Style["text-decoration"] == "underline"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM