Friday, February 15, 2013

SPDataSource and the CrossList DataSourceMode


I was recently searching for how to construct an SPDataSource using a Crosslist or Union of two or more SharePoint lists. Not finding the answer in one place, I was able to piece together the answer. Because we're doing a union of lists, the column names and type in each list must match.


<SharePointWebControls:SPDataSource
runat="server"
ID="spDataSource1"
DataSourceMode="CrossList"
SelectCommand="<Webs Scope='SiteCollection'></Webs>
  <Lists>
    <List ID='XXXXXXXX-XXXX-4499-91F3-359A463EB89F'></List>
    <List ID='XXXXXXXX-XXXX-4EBE-9801-8751A076F069'></List>
  </Lists>
  <View>
    <ViewFields><FieldRef Name='Title' /><FieldRef Name='EventDate' /><FieldRef Name='EndDate' /></ViewFields>
    <Query>
      <Where><Geq><FieldRef Name='EndDate'/><Value  Type='DateTime'><Today/></Value></Geq>
      </Where>
      <OrderBy><FieldRef Name='EventDate' Ascending='True'/></OrderBy>
    </Query>
    <RowLimit>5</RowLimit>
  </View>"

</SharePointWebControls:SPDataSource>

No comments:

Post a Comment