Solved

How to bind xml from web service to gridview

Posted on 2006-10-30
7
518 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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

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…
Sometimes in DotNetNuke module development you want to swap controls within the same module definition.  In doing this DNN (somewhat annoyingly) swaps the Skin and Container definitions to the default admin selections.  To get around this you need t…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Suggested Courses

751 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