Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > Can you set a webpart where condition from the page template? View modes: 
User avatar
Member
Member
vcarter - 8/16/2013 12:53:05 PM
   
Can you set a webpart where condition from the page template?
I want to put some code at the top of my page template that looks like this:
    string curNode = CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeID;
string where = "";

switch (curNode){
case "[NodeID1]":
where = "Region = 1";
break;
case "[NodeID2]":
where = "Region = 2";
break;
case "[NodeID3]":
where = "Region = 3";
break;
case "[NodeID4]":
where = "Region = 4";
break;
}

this.QueryDataSource.WhereCondition = where;
this.QueryDataSource.ReloadData(true);

I have 4 pages that use the same template which populates a uniview based on a custom query. Since they share the template I need to dynamically set the where condition as shown above. When I put that at the top of my template I get the following error.
does not contain a definition for 'QueryDataSource' and no extension method 'QueryDataSource'

Seems like I am missing a reference, can someone help with he syntax?

Thanks

User avatar
Member
Member
vcarter - 8/16/2013 1:58:24 PM
   
RE:Can you set a webpart where condition from the page template?
Solved. This code can be added to a custom layout of a webpart:
 <script runat="server">
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
string curNode = CMS.CMSHelper.CMSContext.CurrentPageInfo.NodeID;
string where = "";

switch (curNode){
case "[NodeID1]":
where = "Region = 1";
break;
case "[NodeID2]":
where = "Region = 2";
break;
case "[NodeID3]":
where = "Region = 3";
break;
case "[NodeID4]":
where = "Region = 4";
break;
}

this.srcElem.WhereCondition = where;
}
</script>

This dynamically sets the where condition for my QueryDataSource control.

User avatar
Certified Developer 12
Certified Developer 12
chetan2309-gmail - 8/21/2013 7:56:42 AM
   
RE:Can you set a webpart where condition from the page template?
How can I use this to set where condition of my query repeater webpart?

User avatar
Member
Member
vcarter - 8/21/2013 8:48:54 AM
   
RE:Can you set a webpart where condition from the page template?
Use the layout attribute of the query webpart, create a custom layout and add your desired code. In my case I am checking the node ID of the page and selecting a regionID based on the page filtering my content.