BUG&FIX: SharePoint Data View column header sorting not working with namespaced XML data

We (Serge van den Oever and Victor Vogelpoel [Macaw]) found a bug with column header sorting within Data View Web Parts when we use a custom web service as the data provider.


It seems that column header sorting is not working without removing the namespace prefix for the header field names in the XSLT of the Data View. When trying to sort in the Data View Web Part the header indicates a sorting order, the ascending and descending arrows are showing, but the actual sorting of the data is not executed.

Let us explain it step-by-step:

We have a web service that produces a non-dataset diffgram result, it actually just produces data in the following format:

<?xml version="1.0" encoding="utf-8" ?>
<ArrayOfAccount xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="urn:my-namespace:webservice:v1">
  <Account>
    <AccountName>Abn Amro</AccountName>
    <AccountCode>ABN</AccountCode>
  </Account>
  <Account>
    <AccountName>Nederlandse Spoorwegen</AccountName>
    <AccountCode>NS</AccountCode>
  </Account>
</ArrayOfAccount>

As you can see in the XML all data is within the namespace “urn:my-namespace:webservice:v1”.

 

In our code we deliver data that comes as an array of the following struct:

public struct Account
{
        public string AccountName;
        public string AccountCode;
}

The web service code is as follows:

[WebService(Namespace = "urn:my-namespace:webservice:v1")]
public class AccountService : WebService
{
  [WebMethod]
  public Account[] GetAccounts()
  {
    ….
  }
}

When we insert a Data View for this web service on a web part page using FrontPage 2003 and enable “Options—>Enable sorting on column headers” on the Data View Web Part, the headers of the columns show up fine in the Data View (AccountName and AccountCode), but the underlying fieldnames for the headers are prefixed with a mapped namespace (ddw1:AccountName and ddw1:AccountCode). This results in the following XSLT code for the header:

:
<th class="ms-vh" nowrap="true">
  <xsl:call-template name="dvt.headerfield" ddwrt:atomic="1">
    <xsl:with-param name="fieldname">ddw1:CompanyName</xsl:with-param>
    <xsl:with-param name="fieldtitle">CompanyName</xsl:with-param>
    <xsl:with-param name="sortable">1</xsl:with-param>
    <xsl:with-param name="attachments">0</xsl:with-param>
  </xsl:call-template>
</th>
:

If the namespace prefix (shown in bold) is removed, sorting start working again!

When a DataSet or DataTable is returned as the result of a web service call this problem does not occur. The reason for this is that the diffgram part of the DataSet or DataTable XML result is not part of the namespace of the web service.

4 Comments

  • You saved my day !!!!

  • Hello,

    Did u find any filtering issues also with custom web service/SoapSource????

    My DVWP is continously telling me "This column type cannot be filtered".

    My web service returns a XML.It does not add any namespace prefix to the data fields.

    Wat could be the reason???

    Wat is confusing is that it works fine when i enable the toolbar for sorting/filtering instead of enabling it on column headers.

    The type is text for all data fields. I do not understand what difficuly sharepoint is facing in filtering the text type.

    Any workarounds.

    Greetings and happy new year.





  • Garfield,

    I am also facing the same issue. Did you figure out the solution?

  • Great! Saved our day.

    However, filtering is still not supported. Any guesses?

    Thanks.

Comments have been disabled for this content.