我有gridview
顯示從數據庫中的數據,如如何從一個gidview數據的jQuery
的ProductID產品名稱價格
A00001蘋果10.00 ADDTOCART
ADDTOCART是一個按鈕。
GridViewRow gr = ((sender as LinkButton).NamingContainer as GridViewRow);
string itemId = gr.Cells[0].Text.Trim();
這些是我使用代碼隱藏的代碼來獲取的ProductID當點擊ADDTOCART
需要幫助的,可以讓變量的代碼我jQuery中宣佈獲得的ProductID像點擊ADDTOCART按鈕時的代碼隱藏功能。
function ShowCurrentTime() {
var name = "The name";//$("#<%=txtUserName.ClientID%>")[0].value; //get the data.
var id = "The id";//$("#<%=TextBox1.ClientID%>")[0].value; //get the data.
$.ajax({
type: "POST",
url: "WebForm1.aspx/GetCurrentTime", //the url and method name of the webmethod
data: "{ name: '" + name + "', id: '" + id + "' }", //pass in 2 data.
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) { //fixed
alert(response.d);
}
});
}
function OnSuccess(response) { //fetching object come out, object inside got name and id, need to specific which data you want by obj.id/obj.name
var obj = response.d; //fetching the webmethod
alert(obj.id + "" + obj.name) //display the return
$('#trycart').append("<li>" + obj.id + "</li>");
$('#cart').append("<tr><td>" + obj.id + "</td><td>" + obj.name +"</td></tr>"); //access the table id=cart, add in the data comeback from webmethod.
}
我需要幫助有變數名稱有產品名稱,和VAR ID有ID,當我點擊ADDTOCART。先謝謝了。
當這個方法「ShowCurrentTime」被叫?點擊按鈕? – Krishna
是的,在buttonclick上,按鈕ADDTOCART – Chris
您是如何將addtocart按鈕的事件處理程序附加到JavaScript方法的?在ShowCurrentTime方法中,您需要獲取單擊的按鈕,然後在按鈕的同一TR中查找文本框,並使用它們的值和if和name一樣。 –