Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
ASP.NET XML作为数据源错误_Asp.net_Xml_Datasource - Fatal编程技术网

ASP.NET XML作为数据源错误

ASP.NET XML作为数据源错误,asp.net,xml,datasource,Asp.net,Xml,Datasource,我试图在ASP中使用XML作为数据源,然后将其显示为datagrid。XML具有以下格式: <?xml version="1.0" encoding="UTF-8"?> <people type="array"> <person> <id type="integer"></id> <first_name></first_name> <last_name></last_

我试图在ASP中使用XML作为数据源,然后将其显示为datagrid。XML具有以下格式:

<?xml version="1.0" encoding="UTF-8"?>
<people type="array">
  <person>
    <id type="integer"></id>
    <first_name></first_name>
    <last_name></last_name>
    <title></title>
    <company></company>
    <tags>
    </tags>
    <locations>
      <location primary="false" label="work">
        <email></email>
        <website></website>
        <phone></phone>
        <cell></cell>
        <fax></fax>
        <street_1/>
        <street_2/>
        <city/>
        <state/>
        <postal_code/>
        <country/>
      </location>
    </locations>
    <notes></notes>
    <created_at></created_at>
    <updated_at></updated_at>
  </person>
</people>
这是我的页面代码

<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="shout._Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
            DataFile="~/App_Data/people.xml" XPath="people/person"></asp:XmlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            DataSourceID="XmlDataSource1">
        </asp:GridView>

    </div>
    </form>
</body>
</html>

无标题页

请帮忙。提前感谢。

gridview不会为列拾取元素,而是在属性之外工作(实际上treeview控件在属性之外工作)。您可以将xml扩展为使用属性,也可以将gridview绑定到codebehind中的数据集(使用数据集的ReadXml方法)


我看到一些建议,将autogeneratecolumns设置为false并使用绑定字段是可行的,但我还没有成功地实现这一点。

您的XML源文件的格式不是XmlDataSource所期望的格式

这个例子很有意义,因为GridView需要某种方法来派生列标题。您的XML文件不提供此功能。另外,它在节点中不包含任何值


我还建议尝试使用Repeater控件,因为它可以让您对显示内容有更多的控制,并且在XML文件的结构上更加自由。有一个很好的例子。

您需要向我们展示更多的代码、gridview绑定和您正在使用的实际数据源(可能是XmlDataSource?),我添加了我的页面代码。希望这能有所帮助。再次感谢。
<%@ Page Language="vb" AutoEventWireup="false" CodeBehind="Default.aspx.vb" Inherits="shout._Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:XmlDataSource ID="XmlDataSource1" runat="server" 
            DataFile="~/App_Data/people.xml" XPath="people/person"></asp:XmlDataSource>
        <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            DataSourceID="XmlDataSource1">
        </asp:GridView>

    </div>
    </form>
</body>
</html>