ASP.NET 2- Can't read data in XML file

Discussion in 'ASP .Net Datagrid Control' started by noone, Apr 1, 2006.

  1. noone

    noone Guest

    Are there any design criteria for XML files that can be used in Visual Web
    Developer.
    I'm using XML Control and Dataview control but the page errors with "no
    data"
    Here's the error when I run the web app
    The data source for GridView with id 'GridView1' did not have any properties
    or attributes from which to generate columns. Ensure that your data source
    has content.
    Is there something that I'm missing or is there a bug?


    Here's a sample of the XML file
    <?xml version="1.0" standalone="yes"?>
    <webstats>
    <app>
    <dir>\\w3svc72802400\\</dir>
    <dns>Fbot</dns>
    <nbserver>\\fiscmmk410win</nbserver>
    <alias>Fbot</alias>
    <sname>fiscmmk410win</sname>
    <port>80</port>
    </app>
    </webstats>
     
    noone, Apr 1, 2006
    #1
    1. Advertising

  2. You need to present your data as attributes rather than as elements to make
    that work:

    "The XmlDataSource control exposes attributes of XML elements as
    data-bindable fields. "

    If you can't change the format of the XML, just use an old-fashioned dataset
    as shown below.

    Let us know if this helps?

    Ken
    Microsoft MVP [ASP.NET]



    <%@ Page Language="VB" %>

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    Protected Sub Page_Load _
    (ByVal sender As Object, _
    ByVal e As System.EventArgs)
    Dim ds As New Data.DataSet
    ds.ReadXml(Server.MapPath("app_data/dta.xml"))
    GridView1.DataSource = ds.Tables(0)
    GridView1.DataBind()
    End Sub
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head runat="server">
    <title>Untitled Page</title>
    </head>
    <body>
    <form id="form1" runat="server">
    <div>
    &nbsp;
    <asp:gridview id="GridView1" runat="server">
    </asp:gridview>
    </form>
    </body>
    </html>


    "noone" <> wrote in message
    news:%...
    Are there any design criteria for XML files that can be used in Visual Web
    Developer.
    I'm using XML Control and Dataview control but the page errors with "no
    data"
    Here's the error when I run the web app
    The data source for GridView with id 'GridView1' did not have any properties
    or attributes from which to generate columns. Ensure that your data source
    has content.
    Is there something that I'm missing or is there a bug?


    Here's a sample of the XML file
    <?xml version="1.0" standalone="yes"?>
    <webstats>
    <app>
    <dir>\\w3svc72802400\\</dir>
    <dns>Fbot</dns>
    <nbserver>\\fiscmmk410win</nbserver>
    <alias>Fbot</alias>
    <sname>fiscmmk410win</sname>
    <port>80</port>
    </app>
    </webstats>
     
    Ken Cox - Microsoft MVP, Apr 3, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Doug
    Replies:
    3
    Views:
    4,378
    Bruce Barker
    Nov 4, 2005
  2. Sanjeev
    Replies:
    4
    Views:
    1,448
    Stanimir Stamenkov
    May 4, 2008
  3. Alex Dowad
    Replies:
    4
    Views:
    273
    Michel Demazure
    May 1, 2010
  4. Ram
    Replies:
    3
    Views:
    253
    Tad McClellan
    Apr 26, 2007
  5. Replies:
    5
    Views:
    86
    Chris Angelico
    May 14, 2014
Loading...

Share This Page