Sharepoint 2007 如何在DataFormWebPart中使用DataSource属性

Sharepoint 2007 如何在DataFormWebPart中使用DataSource属性,sharepoint-2007,web-parts,Sharepoint 2007,Web Parts,我正在编写一个扩展DataFormWebPart的自定义web部件 public class MyCustomWebPart : DataFormWebPart{ // other methods public override void DataBind() { XmlDataSource source = new XmlDataSource() { Data = @"

我正在编写一个扩展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();
        }
     }
公共类MyCustomWebPart:DataFormWebPart{
//其他方法
公共覆盖无效数据绑定()
{
XmlDataSource源=
新建XmlDataSource(){Data=@”
布莱恩
学生
"
};
数据源。添加(源);
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>

最内部标记中的所有值都将消失

发生什么事了?有人能帮我吗


谢谢。

我知道你的问题已经问了好几个月了,但我也遇到了同样的问题,并找到了解决办法

在此MSDN论坛帖子上-

他们提到xsmldatasource xpath导航绑定中有一个bug,解决方法是重写GetXPathNavigator方法

将代码从数据绑定移动到此方法立即解决了查找问题