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

x
?
Solved

asp.net xml

Posted on 2015-02-14
7
Medium Priority
?
116 Views
Last Modified: 2015-02-15
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

Thanks

<Bonds>
<Bond>
    <State>CA</State>
    <BondAmountListing>
      <BondAmount>10000</BondAmount>
      <BondAmount>15000</BondAmount>
     
    </BondAmountListing>
 /Bond>
</Bonds>
0
Comment
Question by:ITsolutionWizard
  • 5
  • 2
7 Comments
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40610522
        private void button1_Click(object sender, EventArgs e)
        {

            XDocument d = XDocument.Load("XMLFile1.xml");

            var amounts = d.Descendants( "BondAmount" );

            foreach ( var amount in amounts)
            {
                MessageBox.Show(amount.Value.ToString());
            }
        }

Open in new window


Make sure to select XMLFile1.xml in the Solution Explorer and hit F4 to change its Copy to Output Directory property to "Copy always"
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40610526
I tested the solution, I got:
xml
I realize that you are using asp but the looping code is the same, In place of MessageBox( user Response.Write(
Mike
0
 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40610530
Here is asp version:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        XDocument d = XDocument.Load("C:\\Users\\Mike\\Documents\\EE\\WebSite5\\XMLFile.xml");

        var amounts = d.Descendants("BondAmount");

        foreach (var amount in amounts)
        {
            Response.Write(amount.Value.ToString() + "\n");
        }
    }
}
0
What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

 
LVL 34

Expert Comment

by:Mike Eghtebas
ID: 40610538
asp outputHere is asp output:
0
 
LVL 1

Author Comment

by:ITsolutionWizard
ID: 40610580
actually i forgot something i want to use gridview and xmldatasource. sorry my bad.
can you show me how? thanks
0
 
LVL 34

Accepted Solution

by:
Mike Eghtebas earned 2000 total points
ID: 40610975
That is okay, you can always post a new question. But close this one because the content needs to match the original post. Even after the gridview question, there will be many other questions coming.

Mean while I prepare the groundwork for your new question.

Mike
0
 
LVL 1

Author Closing Comment

by:ITsolutionWizard
ID: 40611043
no problem. I will post it soon. thank you for your helps.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

783 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