Dynamically set DefaultValue for ParameterBinding to DataFormWebPart

In my custom aspx page in WSS, I use a DataFormWebPart with an xsl file to display some data. To pass values ​​to xsl, I use parameter bindings. In particular, I need to pass the server host URL as follows:

<ParameterBinding Name="HttpHost" Location="CAMLVariable" DefaultValue="http://hardcoded.com" /> 

This works fine, but the next thing I want to do is get the dynamic hostname. So, figuring out how to get this from SharePoint, I added the following binding:

 <ParameterBinding Name="HttpHost" Location="CAMLVariable" DefaultValue='<%# SPContext.Current.Site.Url.Replace (SPContext.Current.Site.ServerRelativeUrl, "") %>' /> 

Now to the problem. The code works as expected if another location on the page is used, but with the above code, SharePoint reports:

Web Part Error: ParameterBindings 'WebPartPages: DataFormWebPart' property does not allow child objects.

Who has this?

Update: I have included server-side code in accordance with this article

+6
sharepoint
source share
2 answers

Well, I found a solution that is not so elegant, but it works.

After several attempts to manage ParameterBindings properties, I thought about how to get the dynamic value there using the Location attribute.

The ParameterBinding Location attribute refers to where to get the value from. Articles such as the "Control ()" option hints. Therefore, changing the parameter binding to:

 <ParameterBinding Name="HttpHost" Location="Control(MyHttpHost, Text)" DefaultValue="" /> 

and adding the following code to my page:

 <asp:TextBox ID="MyHttpHost" runat="server" Visible="false" /> <script runat="server"> protected void Page_Load() { MyHttpHost.Text = SPContext.Current.Site.Url.Replace(SPContext.Current.Site.ServerRelativeUrl, ""); } </script> 

... actually did the trick!

To get the parameter values ​​from the accompanying XSL file, I put param elements in the root element. The parameter name attribute must match the ParameterBinding attribute:

 <xsl:stylesheet ...> ... <xsl:param name="HttpHost"/> 

Then the parameter can be referenced like any other XSL variable.

+5
source share
+2
source share