我正在编写一个扩展DataFormWebPart的自定义web部件。
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作为数据源。
在部署web部件后,我为其设置了以下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部件能像我在后面用C#代码编写的那样显示原始的xml数据。但在web部件中显示的是:
<Person>
<name cap="true" />
<occupation />
</Person>最里面的标记中的所有值都会消失。
到底怎么回事?有人能帮我吗?
谢谢。
发布于 2010-11-19 23:44:16
我知道你的问题已经过去几个月了,但我也遇到了同样的问题,并找到了解决方案。
在这个MSDN论坛上- http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/0a0527b6-3a05-4791-8cc5-9a6de07d23f3
他们提到xsmldatasource xpath导航绑定中存在一个bug,解决方法是覆盖GetXPathNavigator方法。
将代码从数据库绑定到此方法可以立即解决查找问题。
https://stackoverflow.com/questions/2458681
复制相似问题