我在显示从.xml文件中提取信息的gridview时遇到问题。没有错误,只是没有显示在网页(index.aspx)上。
我终于把代码弄到了不会抛出错误的地步,但是现在它根本没有显示在网页上。
我需要创建一个有吸引力的index.aspx,但我只需要首先链接它!
一旦获得此链接,就可以进入我的以下页面,css等。
这里是index.aspx:
<!DOCTYPE html>
<head>
<title>TEST</title>
</head>
<body>
<form id="form1" runat="server">
<asp:GridView ID="purchaseGrid" runat="server" AutoGenerateColumns="false">
<Columns>
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:Label ID="lblRegistrations_ID" runat="server" Text='<%# Bind ("id")%>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Full Name">
<ItemTemplate>
<asp:Label ID="lblRegistrations_FullName" runat="server" Text='<%# Bind ("fullName") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<asp:Label ID="lbl_Email" runat="server" Text='<%# Bind("emailAddress") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Product Name">
<ItemTemplate>
<asp:Label ID="lbl_" runat="server" Text='<%# Bind ("productname") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit Price">
<ItemTemplate>
<asp:Label ID="lbl_UP" runat="server" Text='<%# Bind ("unitprice") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</asp:TemplateField>
<asp:TemplateField HeaderText="Unit quantity">
<ItemTemplate>
<asp:Label ID="lbl_quantity" runat="server" Text='<%# Bind ("quantity") %>'></asp:Label>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</form>
</body>
这是我的尖锐:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Data;
public class purchases : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/purchases.xml"));
purchaseGrid.DataSource = ds;
purchaseGrid.DataBind();
}
}
这是我的xml文档:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<purchases>
<Purchase>
<id>1</id>
<fullName>Keiran Bernal</fullName>
<emailAddress>[email protected]</emailAddress>
<productname>Lab created engagement ring</productname>
<unitprice>5000</unitprice>
<quantity>1</quantity>
</Purchase>
<Purchase>
<id>2</id>
<fullName>Zachery Guy</fullName>
<emailAddress>[email protected]</emailAddress>
<productname>"flowergirl" necklace</productname>
<unitprice>1000</unitprice>
<quantity>1</quantity>
</Purchase>
<Purchase>
<id>3</id>
<fullName>Cordelia Pierce</fullName>
<emailAddress>[email protected]</emailAddress>
<productname>Semi-precious gem ring</productname>
<unitprice>500</unitprice>
<quantity>2</quantity>
</Purchase>
<Purchase>
<id>4</id>
<fullName>Kiana Hawworth</fullName>
<emailAddress>[email protected]</emailAddress>
<productname>Pearl Earrings</productname>
<unitprice>250</unitprice>
<quantity>15</quantity>
</Purchase>
</purchases>
您必须从单价模板中删除多余的部分。它将破坏HTML结构。