[英]Embedded Code in attribute of asp.net controls
我想将面板的可见性绑定到gridview的selectedValue或selectedIndex,所以我尝试这样做:
<asp:Panel ID="pnlPic" Visible='<% gvAllQuarries.SelectedIndex == -1 ? false:true %>' runat="server" >
要么
<asp:Panel ID="pnlPic" Visible='<%= gvAllQuarries.SelectedIndex == -1 ? false:true %>' runat="server" >
但是语法是错误的,对于智能感知来说是未知的。 我怎么能这样绑定? 可能吗?
尝试将事件处理程序放在GridView
的SelectedIndexChanged
事件上; 然后您可以相应地显示/隐藏面板:(VB.NET)
Protected Sub gvAllQuarries_SelectedIndexChanged(sender As Object, e As EventArgs) Handles gvAllQuarries.SelectedIndexChanged
pnlPic.Visible = Not (gvAllQuarries.SelectedIndex = -1)
End Sub
弄乱逻辑,使其按您的意愿进行播放,如有需要,请适应C#。
另外,如果您希望所有面板都内联,则可以将面板包装在条件块中:
VB.NET:
<% If gvAllQuarries.SelectedIndex <> 1 Then%>
<asp:Panel ID="Panel1" runat="server">
//put whatever inside the panel
</asp:Panel>
<% End If %>
C#:
<% if (gvAllQuarries.SelectedIndex != 1) { %>
<asp:Panel ID="Panel1" runat="server">
//put whatever inside the panel
</asp:Panel>
<% } %>
有点混乱,但是我能看到的唯一方法就是不用代码隐藏就可以将它们全部内联。 您正在尝试的选项Visible='<% gvAllQuarries.SelectedIndex == -1 ? false:true %>'
Visible='<% gvAllQuarries.SelectedIndex == -1 ? false:true %>'
仅在使用数据绑定语法( '<%# %>'
)时才起作用,然后无论如何,您都需要从代码背后显式调用DataBind()
。
不幸的是,使用'<%= $>'
只会输出静态文本,不会被评估为布尔值以应用于visible属性。
适应了这个类似的问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.