Dynamically Change the ListID in DFWP
-
09-12-2019 - |
Question
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?
Solution
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();
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange