在一个Repeater控件中,在ItemTemplate中我嵌套了一个Panel控件,检测如果某项字段> 0,那么改Panel的就可见,否则就不可见,写法如下:
<asp:Repeater ID= "rpt " runat= "server " OnItemDataBound= "rpt_ItemDataBound ">
<ItemTemplate>
<asp:Panel id= "panReplyFile " runat= "server " Visible= " <%# ((long)Eval( "infoFileID "))> 0?true:false %> "> ... </asp:Panel>
</ItemTemplate>
</asp:Repeater>
打开此页时总是提示Visible= " <%# ((long)Eval( "infoFileID "))> 0?true:false %> "的格式不正确,换了很多种方式都不行~~
怎么回事了,应该如何设置?
------解决方案--------------------------------------------------------
解释:
Visible 需一个bool值
这样:
Visible= " <%# ((long)Eval( "infoFileID "))> 0?true:false %> "
实际是给Visible赋值 true or false 属string 类型
故改为:Visible= " <%# ((long)Eval( "infoFileID "))> 0%> ">
------解决方案--------------------------------------------------------
Visible= ' <%# (DataBinder.Eval(Container, "infoFileID ").ToString())!= "0 "?true:false %> '>
------解决方案--------------------------------------------------------
Visible= " <%# ((long)Eval( "infoFileID "))> 0? 'true ': 'false ' %> "
------解决方案--------------------------------------------------------
在邦定事件里通过
Panel a = (Panel)e.Row.FindControl( "panReplyFile ");
a.Visible设置
------解决方案--------------------------------------------------------
Visible= ' <%# (DataBinder.Eval(Container, "infoFileID ").ToString())!= "0 "?true:false %> '