我想在ASP中使用XML作爲數據源,然後將其顯示爲數據網格。該XML格式如下:ASP.NET 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>
當我嘗試運行簡單的頁面,我收到以下錯誤
Server Error in '/' Application.
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.
這裏是我的網頁代碼
<%@ 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綁定和您正在使用的實際數據源(XmlDataSource也許?) – Pharabus
我添加了我的頁面代碼。希望這有助於。再次感謝。 –