Click here to Skip to main content
15,665,229 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Dear Sir,

I am Doing a Project in asp.net,

I have used the jquery ajax code to retrieve datas and update the a table.

Here is the Below code that i am used.


JavaScript
$.ajax(
    {
      type: "POST",
      url: "../../GeneralService.asmx/Booked_Items",
      dataType: "json",
      data: {},
      contentType: "application/json; charset=utf-8",
      success: function (json) {

          var xmlDoc = $.parseXML(json.d);
          var xml = $(xmlDoc);
          var customers = xml.find("Table1");

   }
});


Here i have retrieved dataset From web service and i get the values from 'Table1' in 'Customers'.

But i dont know how to show the datas in the aspx page.


Please Help Me.


Thanks

Dileep
Posted

1 solution

Have a gridview in your page, also create the Columns similar to the columns in the dataset table.

XML
<asp:GridView ID="SampleGrid" runat="server" >
</asp:GridView>


Extend your ajax call method to populate the result data.

$.ajax(
                  {
                    type: "POST",
                    url: "../../GeneralService.asmx/Booked_Items",
                    dataType: "json",
                    data: {},
                    contentType: "application/json; charset=utf-8",
                    success: function (json) {
                       
                        var xmlDoc = $.parseXML(json.d);                      
                        var xml = $(xmlDoc);
                        var customers = xml.find("Table1");
                        
                        for (var i = 0; i < customers.length; i++) {
                $("#SampleGrid").append("<table><tbody><tr><td>" + customers[i].Column1 + 
                                            "</td><td>" + customers[i].Column2 + "</td></tr></tbody></table>");
             }
                 }
              });
 
Share this answer
 
Comments
dilzz 22-Aug-12 2:08am    
i am using the Div... so how to bind the datas in div
pramod.hegde 22-Aug-12 2:28am    
Then change gridview to div.
<asp:GridView ID="SampleGrid" runat="server" >

to
<div id="SampleGrid" />

That's it.
dilzz 22-Aug-12 2:53am    
Ho Thank you sir,, Its working.. :)
dilzz 22-Aug-12 3:10am    
Sir, One more doubt, This code is working fine but i didnt get the click event, i have used this code.

$(".photo").click(function () {

alert("asd");
});
pramod.hegde 22-Aug-12 3:18am    
Where is '.photo'?
Looks like this is a 'class' attribute. You can add such attributes while creating <td>, like <td class="photo">. So, what it does is, when you click on this cell, it will show an alert box with message 'asd' in it.

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