如何在代码隐藏变量条件下更改ASPX页面中相关标签的CSS? [英] How to change the CSS of relevant tag in ASPX page on the condition of variable in codebehind?
问题描述
大家好,
Hi all,
<ul id="menu">
<li id="inboxList" style="text-align:right"><a href="#">Inbox(<%=inboxCount%>)</a></li>
<li id="outboxList" style="text-align:right"><a href="#">Outbox(<%=outboxCount%>)</a></li>
<li id="closeList" style="text-align:right"><a href="#">Closed (<%=closeCount%>)</a></li></ul>
我的aspx页面中有一个无序列表。
收件箱(0)
发件箱(0)
已关闭(0)
并在后面的代码中C#我初始化了3个变量。
I have an unordered list in my aspx page.
Inbox (0)
Outbox (0)
Closed (0)
and in the code behind of C# i have initialized 3 variables.
public int inboxCount = 0;
public int outboxCount = 0;
public int closeCount = 0;
某种程度上我正在动态更改这些整数的值。问题是,当任何整数的值大于'0'时,文本应将其CSS更改为粗体,因为我在经典Asp样式中尝试它但它不起作用。
somehow I am changing the values of these integers dynamically. Issue is that when the value of any integer is greater than '0' than the text should change its CSS to bold as I tried it in Classic Asp style but it didn't work.
<%if (inboxCount > 0)
{ %>
<style>
#inboxList
{
font-weight:bold;
color:Black;
}
</style>
</head>
<br />
<%}
%>
Si我将适用其他2个条件。但是不知道它会如何完美地工作..
需要显示如下文字:
收件箱(1)
发件箱(0)
已关闭(0)
请帮忙..
谢谢,
AR :)
Similarly i will apply other 2 conditions like this. But dont know how it will work perfectly..
need to display the text as following:
Inbox (1)
Outbox (0)
Closed (0)
Please help..
Thanks,
AR :)
推荐答案
你可以尝试使用C#背后的代码中的style属性。
请查看以下代码
you can try and use style attribute from the code behind in C#.
please check below code
if(inboxcount >0)
{
inboxList.Style.Add("color","Black");
inboxList.Style.Add("Font-weight","Bold");
}
类似的方式你可以根据你的情况将任何款式应用于其他李。
similar way you can apply any style to other Li based on your condition.
>
这篇关于如何在代码隐藏变量条件下更改ASPX页面中相关标签的CSS?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!