asp.net
  • binding
  • 2013-07-16 119 views 0 likes 
    0

    我想绑定一个面板到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" > 
    

    但对于intelisense,语法是错误的和未知的。我怎么能这样绑定?可能吗?

    回答

    0

    尝试在GridViewSelectedIndexChanged事件中放置事件处理程序;那么你就可以显示/隐藏相应的面板:(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

    +0

    tnx但我想要在标记中,任何方式他们都是一样的。 tnx – Mohammadreza

    +0

    查看更新的答案 – Katstevens

    相关问题