Solved

How to bind xml from web service to gridview

Posted on 2006-10-30
7
519 Views
Last Modified: 2008-01-09
I am looking for an example on how to bind xml results returned from a web service to a gridview.

Regards
0
Comment
Question by:GCaron
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
7 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 17837094
Dim Ds As New DataSet
        Ds.ReadXml(Request.PhysicalApplicationPath + "XMLFile.xml")
        GridView1.DataSource = Ds
        GridView1.DataBind()
0
 
LVL 35

Accepted Solution

by:
YZlat earned 500 total points
ID: 17837128
with the above example you'll have to first write your xml to a file.
If you don't want to do that, try the following:


Dim Ds As New DataSet
Ds.ReadXml(New StringReader(xmlstring))
        GridView1.DataSource = Ds
        GridView1.DataBind()


            
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 17838313
Can you post a portion of what the XML looks like?  Do you have info on how the web service was developed?  If it exposes a dataset as its return type, then it might actually be very easy.  Otherwise, you will need to derive a dataset structure from the XML.  I can get you started on that, but I need to see the XML first.

John
0
Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

 
LVL 12

Expert Comment

by:deanvanrooyen
ID: 17840185
you might be better off using xslt from the returned string, less overhead.
0
 

Author Comment

by:GCaron
ID: 17849826
Thanks, I am able to at lease partially bind the xml to the gridview with limited results. The xml I return from my webservice is in the following format:

<Response>
  <title>title_name</title>
  <result>
   <resulttype>SUCCESS</resulttype>
   <resulttext>0123</resulttext>
   <records>
    <record>
     <id>1234</id>
     <name>John Doe</name>
     <address>1 Main Street</address>
    </record>
   <record>
     <id>1235</id>
     <name>Jane Doe</name>
     <address>2 Main Street</address>
    </record>
   </records>
  </result>
 </Response>

When I perform the bind my gridview only shows the title element. I am trying to display each record in the gridview.

Also, for anyone else viewing this issue, I am using the following method to call the webservice and retrieve the xml:

    public static DataSet getRecords(string strTitle)
    {
        DataSet myDS = new DataSet();

        // initialize object
        myWS.Service MyDNS = new myWS.Service();

        // get AccessCode from web.config file
        string AccessCode = ConfigurationManager.AppSettings["myWS.accesscode"].ToString();

        // make call to myWS webreference that returns and XmlNode
        XmlNode myXMLNodeObject = myWS.selectRecords(AccessCode,strTitle);

        // create new xmldocument object
        XmlDocument myXmlDocumentObject = new XmlDocument();

        // import node we received from mydns call
        myXmlDocumentObject.AppendChild(myXmlDocumentObject.ImportNode(myXMLNodeObject, true));

        //read xmldocument into xmlnodereader
        XmlNodeReader reader = new XmlNodeReader(myXmlDocumentObject);

        //read xml into dataset
        myDS.ReadXml(reader);

       //close reader
       reader.Close();

      //return dataset
        return myDS;
    }


Thanks for any additional insight you can offer.

Regards
0
 

Author Comment

by:GCaron
ID: 17849844
Additionally, on my pageload I use:

        DataSet myDS = Tools.getRecords(strTitle);
        GridView1.DataSource = myDS;
        GridView1.DataBind();

To complete the binding.
0
 

Author Comment

by:GCaron
ID: 17850876
I believe I have what I need. I have inserted the following line:


reader.ReadToFollowing("records");
myDS.ReadXml(reader);

which pushes the reader to the 'records' elements and then passes the items within the to dataset.

If anyone has something more efficient than the methods I am using it would be very much appreciated.

Regards
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

632 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question