0

我有一个显示评论的gridview。我希望如果有人喜欢评论,请按点赞按钮并增加喜欢的总和,但我不想连接到数据库并绑定。我想使用 ajax 来做到这一点。我怎样才能做到这一点?这是我的代码:

<asp:UpdatePanel runat="server" id="UpdatePanel" >
  <ContentTemplate>
    <asp:GridView ID="grdCommentsForLoginnedUser" 
                  runat="server" 
                  AutoGenerateColumns="False" 
                  Width="100%" 
                  OnRowCommand="grdCommentsForLoginnedUser_RowCommand"
                  ViewStateMode="Inherit">
      <Columns>
        <asp:TemplateField >
          <ItemTemplate>
            <asp:HiddenField ID="hdnCommentID" runat="server"
                   Value='<%# Bind("CommentID") %>'/>              
              <table border="2" dir="rtl">
              <tr>
                <td rowspan="2" style="background-color: #6699FF" width="200px">
                  <asp:HyperLink ID="lnkCommenterName"
                        runat="server"
                        NavigateUrl='<%# Bind("CommenterProfile") %>'
                        Text='<%# Bind("CommenterName") %>' />                     
                </td>
                <td width="700px">
                  <br />
                  <asp:Label ID="lblCommentText" runat="server"
                        Text='<%# Bind("CommentText") %>' />
                  <br /> 
                </td>
              </tr>
              <tr>
                <td width="700px">
                  <asp:Label ID="lblPreviousAcceptOrNonAccept" runat="server"
                        Text='<%# Bind("PersonPreviousAcceptOrNonAccept") %>' />
                  <asp:LinkButton ID="lnkBtnRemovePreviousAcceptOrNonAccept" 
                        runat="server"   
                        Text='<%# Bind("RemovePersonPreviousAcceptOrNonAccept") %>'
                        CommandName="RemovePreviousAcceptOrNonAccept" 
                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                  <br />
                  <asp:LinkButton ID="lnkBtnUpRate" runat="server" Text="Like"
                        Visible='<%# Bind("isLikeAndUnlikeButtonVisible") %>'  
                        CommandName="LikeComment" 
                        CommandArgument="<%# ((GridViewRow) Container).RowIndex %>" />
                  <br />sum of likes
                  <asp:Label ID="lblCommentLikes" runat="server"
                             Text='<%# Bind("CommentLikes") %>' />
                </td>
              </tr>
            </table>
          </ItemTemplate>
        </asp:TemplateField>
      </Columns>
    </asp:GridView>
  </ContentTemplate>
</asp:UpdatePanel>
4

1 回答 1

0

onClick向每个按钮添加客户端JavaScript。单击时获取父标记,td然后getElementById("lblCommentLikes")设置.innerText."lblCommentLikes" span

+(theTD.getElementById("lblCommentLikes").innerText)+=1;

或者

+(theTD.getElementById("lblCommentLikes").innerText)-=1;

提示:如果您使用的是 IE,请按 F12 检查DOM正在运行的页面

于 2012-09-09T16:47:36.220 回答