开发者

Setting a style color based on an if/else

开发者 https://www.devze.com 2023-03-13 16:15 出处:网络
<td nowrap valign=\"top\"> <input class=\"formsubmit\" id=\"btnGo\" type=\"button\" value=\"Show Description\"
<td nowrap valign="top">
<input class="formsubmit" id="btnGo" type="button" value="Show Description" 
style = "<%# If (DataBinder.Eval(Container, "DataItem.Exclamation").ToString() == "1")
then Response.Write("color:red") 
Else Response.Write("color:black") EndIf%>" 
OnClick="btnShowDescription('<%#DataBinder.Eval(Container, "DataItem.ListingDescription")%>');" />
</td>
                        `

This is the code for a cell on my table. I'm trying to get it to work but there's a compiler issue saying that I'm missing a closed parentheses which I'm not. (hopefully). Can anyone see what the error could be? I thought I did the if/else logic right. Basically I'm trying 开发者_Python百科to set the font color of a button based on what the value of a certain item in a database.


I think it is because the style=" " is choking on the first double quote?

style = "<%# If (DataBinder.Eval(Container, "<--right here DataItem.Exclamation").ToString() == "1") then Response.Write("color:red") Else Response.Write("color:black") EndIf%>"

Perhaps you need to escape one or more of the quotes?


Try removing the # in front of your If statement i.e. replace

style = "<%# If (DataBinder.Eval(Container, "DataItem.Exclamation").ToString()

with

style = "<% If (DataBinder.Eval(Container, "DataItem.Exclamation").ToString()


use this..

style="<%#  (DataBinder.Eval(Container, "DataItem.Exclamation").ToString() == "1") ? Response.Write("color:red") :Response.Write("color:red")  %>"

OR

style="<%# (Eval("Exclamation").ToString() == "1") ? Response.Write("color:red") :Response.Write("color:red")  %>
0

精彩评论

暂无评论...
验证码 换一张
取 消