抱歉,如果這個問題已經被問過,我很難找到答案。
我正在使用 ASP.NET C# GridView 來系結 XML 檔案中的資料。但是,如果我洗掉根 <BookCollection> 元素,資料只會系結到 GridView。有什么辦法可以保留它并仍然系結嵌套資料?
<?xml version="1.0" encoding="UTF-8"?>
<BookCollection>
<collection>
<Books>
<id>1</id>
<bookName>The Bible</bookName>
<unitprice>50</unitprice>
<quantity>1</quantity>
</Books>
</collection>
</BookCollection>
C# 代碼
DataSet ds= new DataSet();
ds.ReadXml(Server.MapPath("XML file path"));
GridView1.DataSource = ds;
GridView1.DataBind();
我已經嘗試在 GridView 中手動使用 <asp:BoundField DataField="id"/>,但仍然沒有運氣。
感謝幫助。
uj5u.com熱心網友回復:
如果你只需要Books,那么你可以用這個來實作,
GridView1.DataSource = ds.Tables["Books"];
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/452387.html
