<title>
$(function () {
$("[id*=dlCustomers]").hide();
$.ajax({
type: "POST",
url: "CS.aspx/GetCustomers",
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 customers = xml.find("Table");
var repeatColumns = parseInt("<%=dlCustomers.RepeatColumns == 0 ? 1 : dlCustomers.RepeatColumns %>");
var rowCount = Math.ceil(customers.length / repeatColumns);
var i = 0;
while (i < repeatColumns * rowCount) {
var row = $("[id*=dlCustomers] tr").eq(0).clone(true);
for (var j = 0; j < repeatColumns; j++) {
var customer = $(customers[i]);
if (customer.length == 0) {
$("table:last", row).remove();
} else {
$(".name", row).eq(j).html(customer.find("ContactName").text());
$(".city", row).eq(j).html(customer.find("City").text());
$(".postal", row).eq(j).html(customer.find("PostalCode").text());
$(".country", row).eq(j).html(customer.find("Country").text());
$(".phone", row).eq(j).html(customer.find("Phone").text());
$(".fax", row).eq(j).html(customer.find("Fax").text());
$(".image", row).eq(j).attr("src", customer.find("Image").text());
}
i++;
}
$("[id*=dlCustomers]").append(row);
}
$("[id*=dlCustomers] tr").eq(0).remove();
$("[id*=dlCustomers]").show();
}
<asp:datalist id="dlCustomers" runat="server" repeatlayout="Table" repeatcolumns="3" xmlns:asp="#unknown">
CellPadding="2" CellSpacing="2">
<itemtemplate>
<%# Eval("ContactName") %>
| |
City: ]]>
Postal Code: ]]>
Country: ]]>
Phone: ]]>
Fax: ]]>
|
refer link http://aspforums.net/Threads/566882/Populate-ASPNet-DataList-with-Image-by-binding-DataSet-Client-Side-using-jQuery-AJAX/