2010-12-23 81 views
0

我有以下代碼:數據綁定控件和UpdatePanel的

<asp:FormView ID="PhotoFormView" runat="server" DataKeyNames="PhotoID" DataSourceID="PhotoDataSource"> 
    <EmptyDataTemplate> 
     No photo here. 
    </EmptyDataTemplate> 
    <ItemTemplate> 
     <asp:Panel runat="server" Width='<%#PhotoController.FullPhotoSize.Width%>' Style="float: left;"> 
      <asp:UpdatePanel runat="server" UpdateMode="Conditional"> 
       <ContentTemplate> 
        <asp:Button ID="VoteButton" runat="server" OnClick="VotePhoto" /> 
        <asp:Literal ID="VoteCountLL" runat="server" Text='<%#Bind("VoteCount")%>' /> 
        likes <span style="float: right;"> 
         <asp:Button runat="server" Text="Previous" /> 
         <asp:Button runat="server" Text="Next" /> 
        </span> 
       </ContentTemplate> 
      </asp:UpdatePanel> 

在VotePhoto方法(在後面的代碼)由VoteButton按鈕調用的,我試圖調用DataBind上VoteCountLL,但我接收與一個InvalidOperationException 「數據綁定方法如Eval(),XPath()和Bind()只能在數據綁定控件的上下文中使用。」

在英語中,我試圖做的是:我有一張標籤,顯示照片被投票的次數。可以點擊該按鈕以使當前登錄的用戶對照片投票,從而增加投票計數,這發生在VotePhoto方法中。在VotePhoto方法結束時,它會嘗試調用VoteCountLL文字上的DataBind來更新計數,並導致上述異常。我怎樣才能克服這個問題?

回答

0

而不是使用<%#綁定(「VoteCount」)%>,從DataBound事件設置VoteCountLL值可能會有所幫助。