开发者

How to Use DataSource Property in DataFormWebPart

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"/>
  <开发者_如何学C;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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜