In SharePoint 2010 Data view web part, there is no direct way to connect to Data Source of a different site in the same site collection.

What do we do when we need to fetch data from a list residing in the top level site or sub site in SharePoint 2010?

The answer to above question that generally crops up is to use a SOAP Service connection data source and connect data view to this data source.

I feel that we should go to this approach if there is nothing possible directly. The overheads in having another data source is that we have to keep updating the data source in case any column in the list is added. Once we update data source, then we need to update the Data view web part accordingly.

If we use default list data source, things would be pretty easier and there is no overhead.

Hence, I digged down in to the code to find out an alternative for this.

The solution is the usage of parameter viz. WebURL.

Pre-requisite: Configure the Data view web part to use List Name instead of List ID

In Data view web part, there is a tag <ParameterBindings> within which we have several <ParameterBinding> tags.

Add one as given below:

<ParameterBinding Name=”WebURL” Location=”None” DefaultValue=”/sites/top-site-name/”/>

There is a tag viz. <SPDataSources> within which we have <Select> tag.

Modify contents within <Select> tag as given below:

<SelectParameters><WebPartPages:DataFormParameter Name=”WebURL” ParameterKey=”WebURL” PropertyName=”ParameterValues” DefaultValue=”/sites/top-site-name/”/>

The same can be applied to InsertParameters, UpdateParameters, DeleteParameters.

Kindly comment if you are unable to follow the updates or face any issues.