1

I've been trying out the XsltListViewWebPart for SharePoint Foundation 2013. So far I have been able to display my list according the the CAML query defined. Here is my acsx code below:

    <WebPartPages:XsltListViewWebPart runat="server" ViewFlag="" ViewSelectorFetchAsync="False" InplaceSearchEnabled="False" ServerRender="False" ClientRender="True" 
InitialAsyncDataFetch="False" WebId="00000000-0000-0000-0000-000000000000" IsClientRender="False" GhostedXslLink="main.xsl" NoDefaultStyle="TRUE" 
EnableOriginalValue="False" DisplayName="test" ViewContentTypeId="0x" Default="FALSE" ListUrl="" ListDisplayName="" PageSize="-1" UseSQLDataSourcePaging="True" 
DataSourceID="" ShowWithSampleData="False" AsyncRefresh="False" ManualRefresh="False" AutoRefresh="False" AutoRefreshInterval="60" Title="Alarms" FrameType="Default" 
SuppressWebPartChrome="False" Description="" IsIncluded="True" ZoneID="Bottom" PartOrder="2" FrameState="Normal" AllowRemove="True" AllowZoneChange="True" 
AllowMinimize="True" AllowConnect="True" AllowEdit="True" AllowHide="True" IsVisible="True" TitleUrl="" DetailLink="" 
HelpLink="" HelpMode="Modeless" Dir="Default" PartImageSmall="" MissingAssembly="Cannot import this Web Part." PartImageLarge="" IsIncludedFilter="" 
ExportControlledProperties="False" ConnectionID="00000000-0000-0000-0000-000000000000" ID="webPart" __MarkupType="vsattributemarkup" 
__WebPartId="{D6AB9404-8361-4F26-9B27-8FA4A98F1234}" __AllowXSLTEditing="true" WebPart="true" Height="" Width="">
<ParameterBindings>
    <ParameterBinding Name="dvt_sortdir" Location="Postback;Connection"/>
    <ParameterBinding Name="dvt_sortfield" Location="Postback;Connection"/>
    <ParameterBinding Name="dvt_startposition" Location="Postback" DefaultValue=""/>
    <ParameterBinding Name="dvt_firstrow" Location="Postback;Connection"/>
    <ParameterBinding Name="OpenMenuKeyAccessible" Location="Resource(wss,OpenMenuKeyAccessible)" />
    <ParameterBinding Name="open_menu" Location="Resource(wss,open_menu)" />
    <ParameterBinding Name="select_deselect_all" Location="Resource(wss,select_deselect_all)" />
    <ParameterBinding Name="idPresEnabled" Location="Resource(wss,idPresEnabled)" />
    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(core,noXinviewofY_DEFAULT)" />
    <ParameterBinding Name="AddNewAnnouncement" Location="Resource(wss,addnewitem)" />
    <ParameterBinding Name="MoreAnnouncements" Location="Resource(wss,moreItemsParen)" />
</ParameterBindings>
<DataFields>
</DataFields>
<XmlDefinition>
    <View Name="" MobileView="TRUE" Type="HTML" Hidden="TRUE" DisplayName="test" Url="" Level="1" 
        BaseViewID="1" ContentTypeID="0x" ImageUrl="/_layouts/15/images/generic.png" >
        <Query>
            <Where>
                <And>
                    <Geq>
                        <FieldRef Name='Time' />
                        <Value IncludeTimeValue='TRUE' Type='DateTime'>2008-09-29T00:00:00Z</Value>
                    </Geq>
                    <Leq>
                        <FieldRef Name='Time' />
                        <Value IncludeTimeValue='TRUE' Type='DateTime'>2008-09-29T10:00:00Z</Value>
                    </Leq>
                </And>
            </Where>
            <OrderBy><FieldRef Name='Time' /></OrderBy>
        </Query>
        <ViewFields>
            <FieldRef Name="Time"/>
            <FieldRef Name="Phase"/>
        </ViewFields>
        <RowLimit Paged="TRUE">30</RowLimit>
        <Aggregations Value="Off"></Aggregations>
        <Toolbar Type="None"/>
    </View>
</XmlDefinition>

Here is the code behind:

    using (SPSite _site = new SPSite(SPContext.Current.Web.Url.ToString()))
            {
                using (SPWeb _web = _site.OpenWeb())
                {
                    SPList _list = _web.Lists["Test"];
                    this.webPart.ListId = _list.ID;
                    this.webPart.ListName = _list.ID.ToString();
                    this.webPart.ViewGuid = "{3A1B6299-528F-419C-97B4-DECF78381A37}";

                    StringBuilder _xml = new StringBuilder();
                    _xml.Append("<View Name='' MobileView='TRUE' Type='HTML' Hidden='TRUE' DisplayName='' Url='" + Page.Request.Url.ToString() + "' Level='1' BaseViewID='1' ContentTypeID='0x' ImageUrl='/_layouts/images/generic.png'>");
                    _xml.Append("<Query>" +
                                    "<Where>" +
                                        "<And>" +
                                            "<Geq>" +
                                                "<FieldRef Name='Time' />" +
                                                "<Value IncludeTimeValue='TRUE' Type='DateTime'>2008-09-29T00:00:00Z</Value>" +
                                            "</Geq>" +
                                            "<Leq>" +
                                                "<FieldRef Name='Time' />" +
                                                "<Value IncludeTimeValue='TRUE' Type='DateTime'>2008-09-29T10:00:00Z</Value>" +
                                            "</Leq>" +
                                        "</And>" +
                                    "</Where>" +
                                    "<OrderBy><FieldRef Name='Time' /></OrderBy>" +
                                "</Query>");
                    _xml.Append("<ViewFields><FieldRef Name='Time'/><FieldRef Name='Phase'/></ViewFields>");
                    _xml.Append("<RowLimit Paged='TRUE'>30</RowLimit>");
                    _xml.Append("<Aggregations Value='Off'/>");
                    _xml.Append("<Toolbar Type='None'/></View>");
                    this.webPart.XmlDefinition = _xml.ToString();
                }
            }

But when I sort the Time or Phase column, it retrieves all the data regardless of the query. Is there something that I am missing?

0

Going a bit to my grey area here, but have you tried removing the View definition from CAML in code behind? Usually if you define a View, it will take column/sort/etc. definitions from that view instead of what you define in your CAML.

1
  • Yes, I have tried removing the CAML in my code behind but the behavior is still the same.
    – joanna
    Nov 21 '14 at 6:54
0

Try to set HasOverrideSelectCommand property like that:

webPart.HasOverrideSelectCommand = true;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.