Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have a custom application page that I have created a heavily customized DFWP (using jQuery and Kendo UI) but I would like to reuse it across 4 different lists. How can I dynamically change the ListID associated with said web part?

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

I changed the DFWP markup to the following (look for <%# listId %> and QueryString(ID))

<WebPartPages:WebPartZone runat="server" FrameType="None" ID="WebPartZone1" Title="loc:Main"><ZoneTemplate>
        <WebPartPages:DataFormWebPart runat="server" Description="" ID="DFWP1"
            PartOrder="2" Default="FALSE" HelpLink="" AllowRemove="True" 
            IsVisible="True" AllowHide="False" UseSQLDataSourcePaging="True" ExportControlledProperties="True"
            DataSourceID="" Title="MarketNeed" ViewFlag="8" NoDefaultStyle="TRUE" AllowConnect="True" DisplayName="MarketNeed" PageType="PAGE_NEWFORM" 
            FrameState="Normal" PageSize="-1" PartImageLarge="" AsyncRefresh="False" ExportMode="All" Dir="Default" DetailLink="" ShowWithSampleData="False" 
            ListId="<%# listId %>" 
            ListName="<%# listId %>" FrameType="None" PartImageSmall="" IsIncluded="True" 
            SuppressWebPartChrome="False" AllowEdit="True" ManualRefresh="False" ChromeType="None" AutoRefresh="False" AutoRefreshInterval="60" AllowMinimize="True"
             ViewContentTypeId="" InitialAsyncDataFetch="False" MissingAssembly="Cannot import this Web Part." HelpMode="Modeless" 
             ClientIDMode="g_8966a323_abbf_4513_83bb_1ce57b451422" ConnectionID="00000000-0000-0000-0000-000000000000" AllowZoneChange="True" 
            IsIncludedFilter="" __MarkupType="vsattributemarkup" __WebPartId="{8966A323-ABBF-4513-83BB-1CE57B451422}" __AllowXSLTEditing="true" WebPart="true" Height="" Width=""><ParameterBindings>
         <ParameterBinding Name="ListItemId" Location="QueryString(ID)" DefaultValue="0"/>
         <ParameterBinding Name="weburl" Location="None" DefaultValue="http://ctct-dev/sites/plm"/>
         <ParameterBinding Name="ListName" Location="None" DefaultValue="QueryString(ListId)" />
         <ParameterBinding Name="dvt_apos" Location="Postback;Connection"/>
         <ParameterBinding Name="ManualRefresh" Location="WPProperty[ManualRefresh]"/>
         <ParameterBinding Name="UserID" Location="CAMLVariable" DefaultValue="CurrentUserName"/>
         <ParameterBinding Name="Today" Location="CAMLVariable" DefaultValue="CurrentDate"/>
     </ParameterBindings>

These were set using the follwing in code behind:

protected Guid listId;
protected string listName;

protected void Page_Load(object sender, EventArgs e)
{
    SPList list = SPContext.Current.Site.RootWeb.Lists[new Guid(Request.QueryString["List"])];
    listName = list.Title;
    listId = list.ID;
    DataBind();
}
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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