Using XML with ASP.NET

K

ky0t3

I'm trying to add XML to my my ASP.NET project and have it read by
the
gridview control or even the telerik radgrid control either way, it
doesn't work. I get an error about not finding and bindable
properties. Here's a sample of it:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dealers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<dealer_item id="93">
<name>Auburn Harley Davidson</name>
<street>12075 Locksley Ln</street>
<city>Auburn</city>
<state>California</state>
<zip>95602</zip>
<phone>5308857161</phone>
</dealer_item>
<dealer_item id="101">
<name>Backroads Custom Cycle</name>
<street>7939 A E 11th ST</street>
<city>Tracy</city>
<state>California</state>
<zip>95304</zip>
<phone>2098390756</phone>
</dealer_item>
</dealers>


I even tried adding an XSL document to see if that would do the
trick:


<?xml version="1.0" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/
Transform">
<xsl:blush:utput method="html"/>
<xsl:template match="/">


<table border="2" bgcolor="yellow">


<tr>
<td>Title: <xsl:value-of select="dealer_item"/>
</td>
</tr>


<tr><th>Dealer</th><th>Street</th><th>City</th><th>State</
th><th>Zip</
th><th>Phone #</th></tr>
<xsl:for-each select="dealers/dealer_item">
<tr><td><xsl:value-of select="dealer_item"/></td><td><xsl:value-
of
select="street"/></td><td><xsl:value-of select="city"/></
td><td><xsl:value-of select="state"/></td><td><xsl:value-of
select="zip"/></td><td><xsl:value-of select="phone"/></td></tr>
</xsl:for-each>


</table>


</xsl:template>
</xsl:stylesheet>


But that didn't work either. I'm at a loss. I figured this would be
easy but i'm guessing not. I've tried using the XML document with and
without the id="##" and that didn't do any good. Actually, let me
take
that back, it did pop up a column with all the id's but nothing else.


What do you suggest? I'm not keen on retyping the document but it
looks like that might be the only way. I was hoping that I could
input
the data in Excel and dump it out as XML and it'd work like magic.
The
sad thing is, I've seen examples doing it this way (minus the
ID="##")
and it worked fine. I don't know what I'm doing wrong.
 
S

sloan

Option 1:
http://www.aspfree.com/c/a/XML/Applying-XSLT-to-XML-Using-ASP.NET/

Option 2:
http://sholliday.spaces.live.com/Blog/cns!A68482B9628A842A!148.entry

Option 3:
Rework the data. I would create a "strongly typed DataSet", and get the
data into that format.

If it were me, I'd pick between 2 or 3.
#2 if you don't have control over the source xml
#3 if you do have control over the creation of the source xml.


The gridview needs something to bind to. Usually that is row/column based
data.

A (single) table inside of of a DataSet is an example.
A DataView or DataTable is an example.
(among others).
 
A

Alexey Smirnov

ky0t3 said:
I'm trying to add XML to my my ASP.NET project and have it read by
the
gridview control or even the telerik radgrid control either way, it
doesn't work. I get an error about not finding and bindable
properties. Here's a sample of it:

You will need the XmlDataSource control that presents XML to data-bound
controls, such as a GridView.

Here's the complete code for your XML

<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False"
DataSourceID="XmlDataSource1">

<Columns>

<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<%# XPath ("name") %>
</ItemTemplate>
</asp:TemplateField>

<asp:TemplateField HeaderText="Street">
<ItemTemplate>
<%# XPath ("street") %>
</ItemTemplate>
</asp:TemplateField>

</Columns>

</asp:GridView>

<asp:XmlDataSource ID="XmlDataSource1"
runat="server" DataFile="XMLFile1.xml"
XPath="dealers/dealer_item">
</asp:XmlDataSource>
 
G

Guest

Another option would be to just read the XML into a DataSet via its ReadXml
method. Assuming you get the correct table structure using the various
overloads, you can just Databind to the correct table in your DataSet.
Peter
 
K

ky0t3

thanks for your help fellas. I ended up importing the data into an
access database and going that route. it works. not as cool as doing
XML, but it works. i'm going to have to look and spend some studying
on how asp.net works with XML as i'm just not as good as I should be
at it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top