我试图在使用VB的asp中使用GridView,我收到有关内容的错误消息。我做了一些研究并重新格式化了数据源引用的XML文档,但似乎无法生成GridView。
错误消息:“具有id'GridView1'的GridView的数据源没有用于生成列的任何属性或属性。请确保您的数据源具有内容。”
XML代码段:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<financialExpenditures2>
<expenses>
<expense Reporting="" Obj="val" Sub-Obj="" Doc_Code="val" Doc_Dep="val" Document_ID="val" Record_Date="val" FY="val" BFY="val" Acct_Per="val" Fund="val" Department="val" Unit="val" Sub-unit="" Activity="val" Vendor_Code="" Vendor_Name="" Check_Num="" Vendor_Invoice_Num="" Posting_Code="val" Sub_unit="" Posting_Amt="val" Comm_Ln_Num="val" Acct_Ln_Num="val" Accounting_Line_Desc="longer string val"/>
</expenses>
</financialExpenditures>
查看页码
<%@ Page Title="Home Page" Language="vb" MasterPageFile="~/Site.Master" AutoEventWireup="false"
CodeBehind="Default.aspx.vb" Inherits="WebApplication2._Default" %>
<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
<h2>
Welcome to ASP.NET!
</h2>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" DataSourceID="conversionBook2">
</asp:GridView>
<asp:XmlDataSource ID="conversionBook2" runat="server"
DataFile="~/conversionBook2.xml"></asp:XmlDataSource>
</div>
</form>
</asp:Content>
答案 0 :(得分:1)
看起来你的xml文件不太合适。删除financialExpenditures
代码可以解决问题。
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<expenses>
<expense Reporting="" Obj="val" Sub-Obj="" Doc_Code="val" Doc_Dep="val" Document_ID="val" Record_Date="val" FY="val" BFY="val" Acct_Per="val" Fund="val" Department="val" Unit="val" Sub-unit="" Activity="val" Vendor_Code="" Vendor_Name="" Check_Num="" Vendor_Invoice_Num="" Posting_Code="val" Sub_unit="" Posting_Amt="val" Comm_Ln_Num="val" Acct_Ln_Num="val" Accounting_Line_Desc="longer string val"/>
</expenses>