Click here to Skip to main content
15,884,986 members

binding Wcf service datset to grid view through Jquery

Raghava jogu asked:

Open original thread
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

C#
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;

}
Tags: WCF, jQuery, ASP.NET

Plain Text
ASM
ASP
ASP.NET
BASIC
BAT
C#
C++
COBOL
CoffeeScript
CSS
Dart
dbase
F#
FORTRAN
HTML
Java
Javascript
Kotlin
Lua
MIDL
MSIL
ObjectiveC
Pascal
PERL
PHP
PowerShell
Python
Razor
Ruby
Scala
Shell
SLN
SQL
Swift
T4
Terminal
TypeScript
VB
VBScript
XML
YAML

Preview



When answering a question please:
  1. Read the question carefully.
  2. Understand that English isn't everyone's first language so be lenient of bad spelling and grammar.
  3. If a question is poorly phrased then either ask for clarification, ignore it, or edit the question and fix the problem. Insults are not welcome.
  4. Don't tell someone to read the manual. Chances are they have and don't get it. Provide an answer or move on to the next question.
Let's work to help developers, not make them feel stupid.
Please note that all posts will be submitted under the http://www.codeproject.com/info/cpol10.aspx.



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