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:
<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: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>
<WebMethod()> _
Public Shared Function action(ByVal rid As String, ByVal action As String) As String
//DB insertion
End Function