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
             });
         }
 
         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 = "2";
             Type = "POST";
             Url = "Service.svc/GetPatientdetails";
             Data = '{"Id": ""}';
             ContentType = "application/json; charset=utf-8";
             DataType = "json"; ProcessData = true;
             CallService();
         }
 
         function ServiceSucceeded(result) {
 
             if (DataType == "json") {
 
                 resultObject = result.GetPatientdetailsResult;
 
//                 for (i = 0; i < resultObject.length; i++) {
//                     alert(resultObject);
//                                 }

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

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 DamithSL 265
1 CPallini 235
2 OriginalGriff 233
3 Maciej Los 175
4 George Jonsson 170
0 OriginalGriff 5,305
1 DamithSL 4,382
2 Maciej Los 3,760
3 Kornfeld Eliyahu Peter 3,470
4 Sergey Alexandrovich Kryukov 2,901


Advertise | Privacy | Mobile
Web01 | 2.8.141216.1 | Last Updated 7 Feb 2013
Copyright © CodeProject, 1999-2014
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