简体   繁体   English

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

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

i try to highlight record ...like when any one wants to upload documet then in repeater i try to highlight this new record and when user click on this document then this becomes as normal position means not highlight 我试图突出显示记录...就像任何人想要上传文档然后在转发器中我尝试突出显示此新记录,当用户点击此文档时,这将变为正常位置意味着不突出显示

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

but it shows me error 但它显示我的错误

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>

how to solve? 怎么解决?

You can't use control structures (like if statements) inside of a databinding expression tag (which is <%# %> ), but you also can't use DataBinder inside of a regular tag ( <% %> ). 您不能在数据绑定表达式标记( <%# %> )中使用控制结构(如if语句),但也不能在常规标记( <% %> )中使用DataBinder

I'd recommend just using the conditional operater inline like this: 我建议像这样使用条件操作符内联:

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

Try 尝试

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

where 哪里

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

暂无
暂无

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

相关问题 令牌无效 &#39;;&#39; 在类,结构或接口成员声明中 - Invalid token ';' in class, struct, or interface member declaration 令牌无效 &#39;;&#39; 在类struct或接口成员声明中 - invalid token ';' in class struct or interface member declaration 类、结构或接口成员声明中的无效标记“}” - Invalid token '}' in class, struct, or interface member declaration 类、结构或接口成员声明中的无效标记“)”和“{” - Invalid token ')' and '{' in class, struct, or interface member declaration 类,结构或接口成员声明中的令牌&#39;=&#39;无效 - Invalid Token '=' in class,struct or interface member declaration 类、结构或接口成员声明中的无效标记 - Invalid token in class, struct, or interface member declaration 类,结构或接口成员声明中的标记&#39;=&#39;无效,类,结构或接口成员声明中的无效标记&#39;(&#39; - Invalid token '=' in class, struct, or interface member declaration, Invalid token '(' in class, struct, or interface member declaration 我在类,结构或接口成员声明中收到错误的无效令牌&#39;{&#39; - i get error Invalid token '{' in class, struct, or interface member declaration C#-类struct或接口成员声明中的无效令牌&#39;&#39; - C# - invalid token '' in class struct or interface member declaration 类,结构或接口成员声明中的无效令牌“ try” - Invalid token 'try' in class, struct, or interface member declaration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM