0
我正在編寫擴展DataFormWebPart的自定義Web部件。如何使用DataFormWebPart中的DataSource屬性
public class MyCustomWebPart : DataFormWebPart{
// other methods
public override void DataBind()
{
XmlDataSource source =
new XmlDataSource() { Data = @"
<Person>
<name cap='true'>Bryan</name>
<occupation>student</occupation>
</Person>
"
};
DataSources.Add(source);
base.DataBind();
}
}
我唯一需要注意的事情是重寫DataBind()方法,其中我使用xml作爲數據源。
當我部署網絡的一部分,我設置以下XSL到它:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="/">
<xmp>
<xsl:copy-of select="*"/>
</xmp>
</xsl:template>
</xsl:stylesheet>
這XSL將圍繞XML輸入一個標籤。所以我期望Web部分顯示原始XML數據,就像我在C#代碼後面寫的一樣。但在網頁部分顯示的是:
<Person>
<name cap="true" />
<occupation />
</Person>
最內層標籤中的所有值都消失了。
發生了什麼事?有誰能夠幫助我?
謝謝。