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来更新计数,并导致上述异常。我怎样才能克服这个问题?