Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET WCF jQuery
I have written a WCF service for retrieving data from database. and i am storing that in to a data set.then I am calling that service through jQuery service is executing fine and retrieving data also.But Retrieved data is in XML format how can i convert this XML format to normal table to bind grid view using Jquery and also the problem is while i am binding retrieved data set data to grid view using Jquery i am not getting any data in grid view .how can i solve this?Please any one can help me....

and my Jquery Function is
 
var Type;
         var Url;
         var Data;
         var ContentType;
         var DataType;
         var ProcessData;
         //Generic function to call AXMX/WCF  Service
         function CallService() {
             $.ajax({
                 type: Type, //GET or POST or PUT or DELETE verb
                 url: Url, // Location of the service
                 data: Data, //Data sent to server
                 contentType: ContentType, // content type sent to server
                 dataType: DataType, //Expected data format from server
                 processdata: ProcessData, //True or False
                 success: function(msg) {//On Successfull service call
                     ServiceSucceeded(msg);
                 },
                 error: ServiceFailed// When Service call fails
             });
         }
 
<pre>
     function ServiceFailed(result) {
         alert('Service call failed: ' + result.status + '' + result.statusText);
         Type = null; Url = null; Data = null; ContentType = null; DataType = null; ProcessData = null;
     }
 
     function WCFJSON() {
        // var uesrid = &quot;2&quot;;
         Type = &quot;POST&quot;;
         Url = &quot;Service.svc/GetPatientdetails&quot;;
         Data = '{&quot;Id&quot;: &quot;&quot;}';
         ContentType = &quot;application/json; charset=utf-8&quot;;
         DataType = &quot;json&quot;; ProcessData = true;
         CallService();
     }
 
     function ServiceSucceeded(result) {
 
         if (DataType == &quot;json&quot;) {
 
             resultObject = result.GetPatientdetailsResult;

// for (i = 0; i < resultObject.length; i++) {
// alert(resultObject);
// }
 
               var row = $(&quot;[id*=gvpatient] tr:last-child&quot;).clone(true);
            //remove the dummy row we have created
            $(&quot;[id*=gvpatient] tr&quot;).not($(&quot;[id*=gvProducts] tr:first-child&quot;)).remove();
            for (var i = 0; i &lt; resultObject.d.length; i++) {
                //Set product attributes to the row and add it to the gridview
                $(&quot;td&quot;, row).eq(0).html(resultObject.d[i].lblID);
                $(&quot;td&quot;, row).eq(1).html(resultObject.d[i].lblPatientId);
                $(&quot;td&quot;, row).eq(2).html(resultObject.d[i].lblIsPatient);
                $(&quot;td&quot;, row).eq(3).html(resultObject.d[i].lblFirstname);
                $(&quot;td&quot;, row).eq(4).html(resultObject.d[i].lblMiddleinti);
                $(&quot;td&quot;, row).eq(5).html(resultObject.d[i].lblLastname);
                $(&quot;td&quot;, row).eq(6).html(resultObject.d[i].lblBirthdate);
                $(&quot;td&quot;, row).eq(7).html(resultObject.d[i].lblMobileno);
                $(&quot;td&quot;, row).eq(8).html(resultObject.d[i].lblCity);
                $(&quot;[id*=gvpatient]&quot;).append(row);
                //get the copy of the last row again.
                row = $(&quot;[id*=gvpatient] tr:last-child&quot;).clone(true);
 
            }
 
         }
 
     }
 
     function ServiceFailed(xhr) {
         alert(xhr.responseText);
         if (xhr.responseText) {
             var err = xhr.responseText;
             if (err)
                 error(err);
             else
                 error({ Message: &quot;Unknown server error.&quot; })
         }
         return;
     }
 
     $(document).ready(
     function() {
     WCFJSON();
     }
     );</pre>

and my service function

public DataSet GetPatientdetails()
{
 
    string Name = string.Empty;
    // Getting Details from database 
    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["conn"].ConnectionString);
    con.Open();
    SqlCommand cmd = new SqlCommand("sp_per_GetPatientDetails", con);
    cmd.CommandType = CommandType.StoredProcedure;
    SqlDataAdapter da = new SqlDataAdapter();
    DataSet ds = new DataSet();
    da.SelectCommand = cmd;
    da.Fill(ds);
    //SqlDataReader dr = cmd.ExecuteReader();
    //while (dr.Read())
    //{
    //    Name = dr["Per_Firstname"].ToString();
    //}

    con.Close();
    //return Name;
     return ds;
 
}
Posted 6-Feb-13 23:42pm

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

  Print Answers RSS
0 OriginalGriff 455
1 Sergey Alexandrovich Kryukov 445
2 Maciej Los 290
3 ProgramFOX 275
4 CHill60 225
0 OriginalGriff 550
1 Sergey Alexandrovich Kryukov 470
2 Maciej Los 310
3 ProgramFOX 275
4 Peter Leow 250


Advertise | Privacy | Mobile
Web03 | 2.8.150331.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100