如何在 DataFormWebPart 中使用 DataSource 属性
我正在编写一个扩展 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 将使用 tag 包围输入 xml。因此,我希望 Web 部件能够显示我在后面的 C# 代码中编写的原始 xml 数据。但 Web 部件中显示的是:
<Person>
<name cap="true" />
<occupation />
</Person>
最内层标签中的所有值都消失了。
这是怎么回事?有人可以帮助我吗?
谢谢。
I'm writing a custom web part that extends DataFormWebPart.
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();
}
}
The only noticeable thing I do is overriding the DataBind() method, where I use xml as the data source.
After I deploy the web part, I set the following XSL to it:
<?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>
This xsl will surround the input xml with a tag . So I expected the web part to display the original xml data as I wrote in C# code behind. But what shows up in the web part is this:
<Person>
<name cap="true" />
<occupation />
</Person>
All the values within the inner-most tags disappear.
What's going on? Can anybody help me?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我知道你的问题已经过去几个月了,但我也遇到了同样的问题并找到了解决方案。
在此 MSDN 论坛帖子中 - http ://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/0a0527b6-3a05-4791-8cc5-9a6de07d23f3
他们提到 xsmldatasource xpath 导航绑定中有一个错误,并且解决方法是重写 GetXPathNavigator 方法。
将代码从数据绑定移动到此方法立即解决了查找问题。
I know this is several months since your question but I also experienced this same issue and have found the resolution.
On this MSDN forum post - http://social.msdn.microsoft.com/forums/en-US/sharepointdevelopment/thread/0a0527b6-3a05-4791-8cc5-9a6de07d23f3
they mentioned that there is a bug in the xsmldatasource xpath navigation binding, and the resolution is to override the GetXPathNavigator method.
moving code from the databind to this method immediately resolved the lookup issue.