asp.net
  • binding
  • 2013-07-16 118 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

    相關問題