Hello Everyone. I want to insert gridview data to database using Javascript and Ajax and I am almost done. But the main problem is that only last row of gridview is going to the database.
Here is my Javascript code
$(function () {
$("[id*=btnSave]").bind("click", function () {
var product = {};
product.Item = $("[id*=gvDest] tr:last").find("td:nth-child(1)").html();
product.Price = $("[id*=gvDest] tr:last").find("td:nth-child(2)").html();
$.ajax({
type: "POST",
url: "Default.aspx/SaveProduct",
data: '{product: ' + JSON.stringify(product) + '}',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
alert("Product has been added successfully.");
}
});
return false;
});
});
So my question is how can loop through gridview and fetch each row using javascript.
Please help.