Click here to Skip to main content
16,018,534 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
how can i set asp.net datalist itemtemplate label value with json data.
Posted

1 solution

hi Abhijit,
I am not getting your all problem but base on my understanding you can try this, may it is helpful.
JavaScript
function myfunction() {
    $.ajax(
     {
         cache: false,
         url: "url", // or your url
         success: function (result) { //result is your json object which you have return from your server function. 
             for (var i = 0; i < result.length; i++) {
              alert(result[i].fieldname); // or Set to label  like   $("#labelId").val(result[i].fieldname) or by CssClass;
              }

         }
     });
}   


For more Prepare a JSON Web Service and access it with JQuery[^]
 
Share this answer
 
v2
Comments
Abhijit Barua 26-Jun-12 3:55am    
thank you,
i have datalist with itemtemplate have label like below...
<asp:DataList ID="DataList1" runat="server">

<itemtemplate>
<table><tr><td><asp:Label ID="Label3" runat="server"></td></tr>
<tr><td> <asp:Label ID="Label4" runat="server"></td></tr>
</table>






i use webservice to send data to json....i got data at json...and i use jquery to bind datalist like below...
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js"></script>

<script type="text/javascript">
$(document).ready(function () {
$("#getData").click(function () {

$.ajax({
url: "WebService.asmx/GetStudents",
data: "{}",
dataType: "json",
type: "POST",
contentType: "application/json; charset=utf-8",
success: function (data) {
$(data.d).each(function (index, item) {

var lable = document.getElementById("<%=Label3.ClientID %>");

for (var i = 0; i < data.d.length; i++) {

//here what i have to write.........
};


});
},
error: function (a, b, c) {
}
});
});
});
</script>

but i not able to bind datalist. plz help me....

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900