尝试在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 %>'
的选项将仅适用,然后您需要从代码隐藏中明确地调用DataBind()
。
不幸的是,使用'<%= $>'
只会输出静态文本,而不会将其评估为布尔值以应用于visible属性。
改编自this similar question。
tnx但我想要在标记中,任何方式他们都是一样的。 tnx – Mohammadreza
查看更新的答案 – Katstevens