[英]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.