0

コメントを表示するグリッドビューがあります。人がコメントを気に入ったら、いいねボタンを押していいねの合計を増やしたいのですが、データベースに接続してバインドしたくありません。私は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

各ボタンにクライアント側のonClickJavaScript を追加します。クリックすると親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 に答える