Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

asp.net xmldatasource

Posted on 2015-02-15
11
Medium Priority
?
71 Views
Last Modified: 2015-02-16
Can you show me how to call BondAmount in asp.net/c# ?
I basically want to get the list of bond amount so i will be

10000
15000

and I would like to use xmldatasource and gridview as front end.

Thanks

<Bonds>
<Bond>
    <State>CA</State>
    <BondAmountListing>
      <BondAmount>10000</BondAmount>
      <BondAmount>15000</BondAmount>
     
    </BondAmountListing>
 /Bond>
</Bonds>
0
Comment
Question by:ITsolutionWizard
  • 6
  • 4
11 Comments
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 2000 total points
ID: 40611203
I revised the XML a bit for test purpose (I was getting errors with your version):
<?xml version="1.0" encoding="utf-8" ?>
<Bonds>
  <Bond ID="1">
     <State>CA</State>
      <BondAmount>10000</BondAmount>
    </Bond>
  <Bond ID="2">
    <State>CA</State>
    <BondAmount>15000</BondAmount>
  </Bond>
  <Bond ID="3">
    <State>MA</State>
    <BondAmount>8000</BondAmount>
  </Bond>
  <Bond ID="4">
    <State>MA</State>
    <BondAmount>9000</BondAmount>
  </Bond>
  </Bonds>

Open in new window

Using this code: (make sure to add: using System.Data;)
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataSet ds = new DataSet();
        ds.ReadXml(MapPath("~/XMLFile1.xml"));
        GridView1.DataSource = ds;
        GridView1.DataBind();
 
    }

Open in new window

I got this:xml to gv
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611266
Ic but I would like to keep my way in xml. Is it possible?
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611286
I found the error:

    </BondAmountListing>
 </Bond>      // < was missing.
</Bonds>

I tried different variations of it but I was not able to figure it out. I guess I need to learn more about xml myself.
I can post a new question on that saying I have this c# code that works with this xml but not the other one (the one you have). then I let you know about the solution. Or, you can post it yourself.

Let me know which way you prefer.

Mike
0
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611297
try below
</Bond>   is mssing "/", and i correct below. I think the xml is valid.


<Bonds>
<Bond>
    <State>CA</State>
    <BondAmountListing>
      <BondAmount>10000</BondAmount>
      <BondAmount>15000</BondAmount>
     
    </BondAmountListing>
< /Bond>
</Bonds>
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611302
Overall, I appreciate your helps but I need to keep using same xml file format because it is currently in production website.
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611321
I suppose you neither want me to post the question nor you want to do it yourself. Then, I am sure another expert will join and make contribution you need.

Thanks,

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611336
I would suggest to delete this question (refunding the points) and then posting a new question because with zero comments on a question, you will have a better chance of getting quick response.

BTW, I check your xml file at http://www.xmlvalidation.com/ and there was no error. I think xPath query will do the job.

Mike
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40611546
I try xpath but always return first record only
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611631
I will invite another expert who often helps me with my question. I am sure he will a solution right away.

Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40611645
re: I try xpath but always return first record only

With the code I have submitted, using your xml file I also get result similar to yours. Now, there are two possibilities:

A: Your xml design is not good and that is why it is not producing the expected result.
B: Your xml is good and someone who knows how to handle it needs to take a look at it.

I sent an email to Fernando Soto to take a look at this question and teach us how it is done.

Mike
0
 
LVL 64

Expert Comment

by:Fernando Soto
ID: 40612293
Hi ITsolutionWizard and Mike;

I wish I can help with this question but do not have the expertise to help. What I can tell you is the current XML document will NOT be able to be displayed in the GridView because it works with XML Attributes and NOT inner values. That said you have two options. First is to modify the XML document so that the values are Attributes of the node. But you stated that you can not do that, so the only option is to transform the XML document into the correct format. So you must create a XSLT document describing how do you want to transform the XML document into the correct format. When you have this document added into your project when you configure the XmlDataSource you provide the path to the file to the, Transform File Property. Because XSLT documents are Greek to me I can not direct you in this matter.

Maybe you can post a new question specifically asking help in creating an XSLT document to convert your XML at runtime.
0

Featured Post

Technology Partners: 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!

Question has a verified solution.

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

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Suggested Courses

886 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