使用json自动增量计数器(与按钮不同) [英] Autoincrement counter (like and unlike buttons) using json
本文介绍了使用json自动增量计数器(与按钮不同)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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
推荐答案
( [id * = lnkagree])。live( 点击, function (){
var id =
("[id*=lnkagree]").live("click", function () { var id =
( this )。attr(' CommandArgument');
var act =
(this).attr('CommandArgument'); var act =
( this )。 attr(' CommandName');
if (id!= ' '&& act!= ' '){
(this).attr('CommandName'); if (id != '' && act != '') {
这篇关于使用json自动增量计数器(与按钮不同)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文