This post is about how you can read the data from one sub-site to another sub-site. As a special note, I am not talking about how to access data from one site to another inside the same site collection. Is a common confusion to name site collection what is actually top level site.
As a practical example for this article, we need to display data from a sub-site called “Primary Site”, with URL “/PrimarySite”, into a drop down list control placed in a page inside “Secondary Site”, with URL “/SecondarySite”. Need to mention the top level site has the following URL: domain.com/sites/toolkit/.
To do the task, all you need are several lines:
<SharePoint:DVDropDownList runat="server" DataSourceID="SourceOfData" DataValueField="Title" DataTextField="Title"> </SharePoint:DVDropDownList> <SharePoint:SPDataSource runat="server" DataSourceMode="List" ID="SourceOfData" SelectCommand='<![CDATA[<View></View>]]>'> <SelectParameters> <asp:Parameter Name="ListName" DefaultValue="Data Source List" /> <asp:Parameter Name="WebUrl" DefaultValue="/sites/toolkit/PrimarySite" /> </SelectParameters> </SharePoint:SPDataSource> </asp:Content>
Please note importance and effect of WebUrl select parameter, which should be composed from URL of the parent site (excluding of course domain.com part) and URL of the sub-site where list to serve as data source is created.