<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>
`
这是我桌子上的单元格的代码。我试图让它工作但是有一个编译器问题说我错过了一个我不是的封闭括号。 (希望)。任何人都可以看到错误是什么?我以为我做了if / else逻辑。基本上我正在尝试根据数据库中某个项的值来设置按钮的字体颜色。
答案 0 :(得分:0)
尝试删除If语句前面的#,即替换
style =“&lt;%# If(DataBinder.Eval(Container,”DataItem.Exclamation“)。ToString()
带
style =“&lt;%If(DataBinder.Eval(Container,”DataItem.Exclamation“)。ToString()
答案 1 :(得分:0)
我认为这是因为style=" "
在第一个双引号上窒息了?
style =“&lt;%#If (DataBinder.Eval方法(容器, “&lt; - 就在这里 DataItem.Exclamation”)。ToString()== “1”)然后Response.Write(“color:red”) 否则Response.Write(“颜色:黑色”) ENDIF%&gt;“中
也许你需要逃避一个或多个引号?
答案 2 :(得分:0)
使用此.. ..
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") %>