Monday, September 8, 2008

ListID fix for the DataView webpart

Scenario:
You want to use a ListView webpart on your page, but ListView is tied to a ListID which will not be the same ListID in any other environment.

Fix:
Open the ListView in SharePoint Designer and tie it to ListName ( Tasks in this example) rather than ListView ID

Code:

<%@ Register TagPrefix="sharepoint" Namespace="Microsoft.SharePoint.WebControls"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<%@ Register TagPrefix="webpartpages" Namespace="Microsoft.SharePoint.WebPartPages"
Assembly="Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>

<sharepoint:SPDataSource runat="server" DataSourceMode="List" SelectCommand="&lt;View&gt;&lt;Query&gt;&lt;OrderBy&gt;&lt;FieldRef Name=&quot;ID&quot;/&gt;&lt;/OrderBy&gt;&lt;/Query&gt;&lt;/View&gt;" UpdateCommand="" InsertCommand="" DeleteCommand="" UseInternalName="True" IncludeHidden="True" ID="datasource1">


<SelectParameters>
<webpartpages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Tasks" Name="ListName">
</webpartpages:DataFormParameter>

<asp:QueryStringParameter QueryStringField="RootFolder" Name="RootFolder" Type="String"></asp:QueryStringParameter>
<asp:Parameter DefaultValue="0" Name="StartRowIndex"></asp:Parameter>
<asp:Parameter DefaultValue="0" Name="nextpagedata"></asp:Parameter>
<asp:Parameter DefaultValue="100" Name="MaximumRows"></asp:Parameter>

</SelectParameters>

<UpdateParameters>
<webpartpages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Tasks" Name="ListName">
</webpartpages:DataFormParameter>
</UpdateParameters>

<InsertParameters>
<webpartpages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Tasks" Name="ListName">
</webpartpages:DataFormParameter>
</InsertParameters>

<DeleteParameters>
<webpartpages:DataFormParameter ParameterKey="ListName" PropertyName="ParameterValues" DefaultValue="Tasks" Name="ListName">
</webpartpages:DataFormParameter>
</DeleteParameters>
</sharepoint:SPDataSource>


Articles:
SPDataSource for every sharepoint developer

SPDatasource every developer friend

SPDatasource fields for webs listsoflists

Rollups with the data view

http://sharepointdevwiki.com/display/public/Accessing+List+Items+using+SPDataSource+using+the+object+model

3 comments:

Unknown December 26, 2009 at 2:17 AM  

I have read in different articles to change ListId to ListName to avoid any problem in deployng DVWP to any other system. My problem is that i am using a list of another site in my DVWP. Basically the list in on root site while the page on which it is using via DVWP is on a subsite 2 levels below from root site. So i think only changing ListID to ListName will not be enough.

Can you tell me how to configure my new DVWP so that it can be deployed on other system where there will be list of same name on root site?

Unknown December 26, 2009 at 2:20 AM  

I have read in different articles to change ListId to ListName to avoid any problem in deployng DVWP to any other system. My problem is that i am using a list of another site in my DVWP. Basically the list in on root site while the page on which it is using via DVWP is on a subsite 2 levels below from root site. So i think only changing ListID to ListName will not be enough.

Can you tell me how to configure my new DVWP so that it can be deployed on other system where there will be list of same name on root site?

Sandeep December 26, 2009 at 2:26 AM  

check this
http://www.endusersharepoint.com/2009/12/11/display-a-sharepoint-list-on-another-site/