Hi,
I want to access ASP.net Gridview control i.e. bind data into gridview control from static method(ajax webmethod). How can I do this.
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
gunjan aroraPosted Jun 19, 2014, 12:04 AM
Dhanunjay JajimogglaPosted Jun 17, 2014, 9:19 AM
Call the your static method from javascript using pageMethods. bind data to your Gridview in javascript.
function GetData() {
$.ajax({
type: "POST",
url: "Your.aspx/getData",
data: data .
contentType: "application/json; charset=utf-8",
dataType: "json",
success: OnSuccess,
failure: function (response) {
alert(response.d);
},
error: function (response) {
alert(response.d);
}
});
}
function OnSuccess(response) {
var xmlDoc = $.parseXML(response.d);
var xml = $(xmlDoc);
var Table= xml.find("Table");
var row = $("[id*=Gridview1] tr:last-child").clone(true);
$("[id*=Gridview1] tr").not($("[id*=Gridview1] tr:first-child")).remove();
$.each(Table, function () {
var customer = $(this);
$("td", row).eq(0).html($(this).find("Column1").text());
$("td", row).eq(1).html($(this).find("Column2").text());
$("td", row).eq(2).html($(this).find("Column3").text());
$("[id*=gvCustomers]").append(row);
row = $("[id*=Gridview1] tr:last-child").clone(true);
});
}