Click here to Skip to main content
15,895,011 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
XML
Hello dear ones,



i want to have 2 buttons in a <asp:datagrid> , say like and unlike buttons, i want to increment each click and save in database along with the user's ID. i am asked to use json jquery, further process using webservice to which i am very new.

could you please help with with complete code? i am in trouble



Here is the code, please feel free to modify the way you want:


JavaScript
<script type=""mce-text/javascript"">{  
        $("[id*=lnkagree]").live("click", function () {  
            var id = $(this).attr('CommandArgument');  
            var act = $(this).attr('CommandName');  
   
            if (id != '' && act != '') {  
                $.ajax({  
                    type: "POST",  
                    contentType: "application/json; charset=utf-8",  
                    url: "Default.aspx/action",  
                    data: "{'id':'" + id + "','action':'" + act + "'}",  
                    dataType: "json",  
                    success: function (data) {  
                        var obj = data.d;  
                        if (obj == 'true') {  
   
                        }  
                    },  
                    error: function (result) {  
                        pnl_login.Visible = True;  
                        txteml.Focus();  
                        alert("Error");  
                    }  
                });  
            }  
            else {  
                alert('')  
                return false;  
            }  
   
            return false;  
        });  
       
</script>  



ASP.NET
<asp:DataGrid ID="sample" runat="server" >  
      <Columns>  
                                                            <asp:TemplateColumn>  
                                                                   
                                                                <ItemTemplate >  
                                                             
                                                                             <asp:ImageButton runat="server" ID="lnkagree"   ImageUrl="~/likesml.png" ClientIDMode="Static"  
                                                                                    CausesValidation="False" CommandName="Like" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "id")%>' /><asp:Image ID="liked" runat="server" Visible="false" ImageUrl="~/liked.png" />  <asp:Label  runat="server" ID="like_no" ForeColor="Green"  Text='<%#DataBinder.Eval(Container.DataItem, "flike")%>'></asp:Label>  
                                                                                      
                                                                                       
                                                                                <asp:ImageButton runat="server" ID="lnkdisagree" ImageUrl="~/dislikesml.png" ClientIDMode="Static"  CausesValidation="False" CommandName="Dislike" CommandArgument='<%#DataBinder.Eval(Container.DataItem, "id")%>'  />  
                                                                                    <asp:Image ID="disliked" runat="server" Visible="false" ImageUrl="~/disliked.png" />  
                                                                                    <asp:Label   runat="server" ForeColor="Red" ID="dislike_no" Text='<%#DataBinder.Eval(Container.DataItem, "fdislike")%>'></asp:Label>  
                                                                                  
                                                                            </div>  
  
  
                                                                </ItemTemplate>  
                                                            </asp:TemplateColumn>  
       </Columns>  
                                                         
   </asp:DataGrid>  





VB
<WebMethod()> _  
    Public Shared Function action(ByVal rid As String, ByVal action As String) As String  
   
//DB insertion  
   
End Function  
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900