Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7024209
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:48:39+00:00 2026-05-27T23:48:39+00:00

I am using ASP.Net 2.0 and trying to display transformed xml data using GridView

  • 0

I am using ASP.Net 2.0 and trying to display transformed xml data using GridView and XMLDataSource at run time.

Here is my xml data (Input.xml):

<catalog>
<cd>
    <title>Empire Burlesque</title>
    <artist>Bob Dylan</artist>
    <country>USA</country>
    <company>Columbia</company>
    <price>10.90</price>
    <year>1985</year>
</cd>
<cd>
    <title>Hide your heart</title>
    <artist>Bonnie Tyler</artist>
    <country>UK</country>
    <company>CBS Records</company>
    <price>9.90</price>
    <year>1988</year>
</cd>
<cd>
    <title>Greatest Hits</title>
    <artist>Dolly Parton</artist>
    <country>USA</country>
    <company>RCA</company>
    <price>9.90</price>
    <year>1982</year>
</cd>
<cd>
    <title>Still got the blues</title>
    <artist>Gary Moore</artist>
    <country>UK</country>
    <company>Virgin records</company>
    <price>10.20</price>
    <year>1990</year>
</cd>
</catalog>

And here is the transform (Transform.xslt):

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:template match="/">
    <CDCatalog>
        <xsl:apply-templates/>
    </CDCatalog>
</xsl:template>

<xsl:template match="cd">
  <CD>
  <xsl:apply-templates select="*">
        </xsl:apply-templates>
  </CD>
</xsl:template>


<xsl:template match="catalog/cd/*">
            <xsl:attribute name="{local-name()}">
        <xsl:value-of select="."/>
    </xsl:attribute>
</xsl:template>

</xsl:stylesheet>

And for your reference this would be the transformed xml:

<CDCatalog>
<CD title="Empire Burlesque" artist="Bob Dylan" country="USA" company="Columbia" price="10.90" year="1985"/>
<CD title="Hide your heart" artist="Bonnie Tyler" country="UK" company="CBS Records" price="9.90" year="1988"/>
<CD title="Greatest Hits" artist="Dolly Parton" country="USA" company="RCA" price="9.90" year="1982"/>
<CD title="Still got the blues" artist="Gary Moore" country="UK" company="Virgin records" price="10.20" year="1990"/>
</CDCatalog>

Now this what I am doing in my C# code (GridView1 is created on .aspx page):

        XmlDataSource xmlDS = new XmlDataSource();
        xmlDS.EnableCaching = false;
        xmlDS.DataFile = "~/Input.xml";
        xmlDS.TransformFile = "~/Transform.xslt";
        xmlDS.XPath = "/CDCatalog/CD";
        GridView1.DataSourceID = xmlDS.ID;
        GridView1.DataBind();
        GridView1.Visible = true;

I do not see any data in the GridView. I looked up quite a bit on the internet but they generally talk about doing this sort of thing at design time in the aspx page but not at run time with in the code. I am not sure if this is a limitation on GridView/XMLDataSource binding or if I am doing something wrong. I appreciate any help on this.
Thanks, Srinivas

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:48:40+00:00Added an answer on May 27, 2026 at 11:48 pm

    Simply change this line:

    GridView1.DataSourceID = xmlDS.ID;
    

    to this:

    GridView1.DataSource = xmlDS;
    

    enter image description here

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using c# asp.net, just trying to display data in a read-only format once
I am new to ASP.NET. I am trying to display my sql results using
I am trying to display a 'Software Release' table in an asp.net dynamic data
I'm using the wcf webapi to get data from my asp.net application, and trying
I'm beginner in Asp.Net and Im trying to display gc on reapet control. Here's
Using ASP.NET MVC when trying to get the information stored on my Session[objectName] from
I'm using asp.net mvc2 and trying to send a list of json objects with
Link I'm using ASP.NET with C# and trying to use linq to sql to
I am using asp.net and I am trying to save checkbox values into a
I'm using ASP.NET MVC Framwork and trying to grok the ASP Membership 3.5 stuff.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.