繁体   English   中英

类,结构或接口成员声明中的标记'else'无效

[英]Invalid token 'else' in class, struct, or interface member declaration

我试图突出显示记录...就像任何人想要上传文档然后在转发器中我尝试突出显示此新记录,当用户点击此文档时,这将变为正常位置意味着不突出显示

<tr style='<%#if(DataBinder.Eval(Container.DataItem, "ViewedType")== 1) 
 { %> background-color: yellow;  <% }
   else { <% background-color: white;
    <%} %>'>

但它显示我的错误

CS1519: Invalid token 'else' in class, struct, or interface member declaration

Source Error:

Line 128:  style='<%#if(DataBinder.Eval(Container.DataItem, "ViewedType")== 1) 
Line 129:  { %> background-color: yellow;  <% }
Line 130:  else { <% background-color: white;
Line 131:  <%} %>'>
Line 132:  <%--<td>

怎么解决?

您不能在数据绑定表达式标记( <%# %> )中使用控制结构(如if语句),但也不能在常规标记( <% %> )中使用DataBinder

我建议像这样使用条件操作符内联:

<tr style='background-color: <%# (bool) DataBinder.Eval(Container.DataItem, "ViewedType") ? "yellow" : "white" %>'>

尝试

<tr style='background-color: <%# ChooseColor((int)DataBinder.Eval(Container.DataItem, "ViewedType")) #>;'>

哪里

protected string ChooseColor(int viewedType){
    if (viewedType == 1) return "yellow"; else return "white";
}

暂无
暂无

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

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