Portal Engine Questions on portal engine and web parts.
Version 7.x > Portal Engine > K# syntax help View modes: 
User avatar
Member
Member
vcarter - 1/23/2014 9:54:45 AM
   
K# syntax help
 <cms:queryrepeater StopProcessing="false" runat="server" ID="rLatestNews" WhereCondition="" QueryName="custom.news.FilterByBusinessAndRegion" TransformationName="custom.news.NewsLatestSetPath" OrderBy="NewsReleaseDate DESC" />

Is there a k# equivalent to ASCX transformation controls?

I am creating a dynamic spotlight section on my homepage and I am using a type variable to populate the boxes. Problem is:
<% if (Convert.ToInt32(Eval("SpotlightType")) == 2) { %>
<td>
<%# Eval("SpotlightCustomText")%>
<a href="<%# Eval("SpotlightURL")%>" class="more">Learn More</a>
</td>
<%} %>

This doesn't work. Oddly I have code where something like this does work, but in this case it either gives me a string vs integer error, or as in this case it simply does not evaluate.

I have however gotten this to work in k#, but I need a nested repeater so that I can add the option for a "Latest News" box. Just don't know the syntax to do that in K#.

Any help would be appreciated.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/23/2014 10:57:41 AM
   
RE:K# syntax help
I wonder if its a data type conversion issue. Check out the functions you can use out of the box with Kentico that replace pretty much all the Convert... functions
• Eval(string columnName)
• Eval(string columnName, bool encode)
• Eval<ReturnType>(string columnName)
• EvalHTML(string columnName)
• EvalJSString(string columnName)
• EvalText(string columnName)
• EvalInteger(string columnName)
• EvalDouble(string columnName)
• EvalCDATA(string columnName)
• EvalDateTime(string columnName)
• EvalGuid(string columnName)
• EvalBool(string columnName)
• EvalCDATA(string columnName, bool encapsulate)
• GetEditableValue(string controlId)

I'd suggest using
EvalInteger("SpotlightTpe) == 2
or even CMS.GlobalHelper.ValidationHelper.GetInteger(Eval("SpotlightType"), 0) == 2

User avatar
Member
Member
vcarter - 1/23/2014 11:32:11 AM
   
RE:K# syntax help
Thanks FroggEye, still not working. So odd. I have another transformation for another type where I use the same syntax, the only difference is that I am checking a variable I added to a custom query. Same exact syntax though.

Oh, well. I will just try and figure out another way(I am sure there is a better one LOL) to accomplish the task.

Thanks again.

User avatar
Kentico Legend
Kentico Legend
Brenden Kehren - 1/23/2014 1:20:24 PM
   
RE:K# syntax help
If you copied and pasted, I had incorrect syntax, I was missing the closing ". Also another thing I do since I don't check items out the file system very often, is copy and paste the syntax into an ascx file for verification with Visual Studio.

User avatar
Member
Member
vcarter - 1/23/2014 1:40:13 PM
   
RE:K# syntax help
The issue seems to be with my return field.
<%# Eval("SpotlightType") %>

No matter how I cast it. Kentico will only display it as output. Any evaluation of that comes up blank. I even tried to apply another solution you had given me(using code)
<script runat="server">
protected int setSpotType (){
string curType = EvalText("SpotlightType",true);
int spotType = 0;
switch (curType){
case "1":
spotType = 1;
break;
case "2":
spotType = 2;
break;
case "3":
spotType = 3;
break;
case "4":
spotType = 4;
break;
}

return spotType;
}
</script>

The case statement works fine if I hard code a value in place of "SpotlightType" but doesn't evaluate otherwise.

Honestly the whole thing seems odd to me. I have tries EvalInteger as well, nothing seems to work. I will figure it out eventually. Thanks again.

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/23/2014 1:54:00 PM
   
RE:K# syntax help
Try this:
Im assuming that the spotlighttype field is an integer because your switch statement is comparing to integers...

int curType = EvalText(Convert.ToInt32("SpotlightType"),0);

User avatar
Certified Developer 10
Certified Developer 10
josha-bpstudios - 1/23/2014 1:54:44 PM
   
RE:K# syntax help
int curType = EvalText(Convert.ToInt32("SpotlightType")),0);

Sorry, this is the correct one, the one above didn't have the last ")".

User avatar
Member
Member
vcarter - 1/24/2014 9:12:52 AM
   
RE:K# syntax help
I tried that too josha. Still working on it.

User avatar
Member
Member
vcarter - 1/27/2014 9:01:12 AM
   
RE:K# syntax help
Is there a "correct" syntax, for something like this:

{^QueryRepeater|(QueryName)custom.news.FilterByBusinessAndRegion(TransformationName)custom.news.NewsLatestSetPath^}


My conditionals won't evaluate in the ASCX transformation type and I really need to have a nested control. So Text/XML seems to be required. Is this possible, or am I spinning my wheels?

User avatar
Member
Member
vcarter - 1/27/2014 10:07:46 AM
   
RE:K# syntax help
<%# Eval<int>("SpotlightType")==2 %>


That evaluates to true or false depending on the value of "SpotlightType". Which makes sense.

Neither:

<% if ((Eval<int>("SpotlightType")==2) == true) { %>


or

<% if (Eval<int>("SpotlightType")==2) { %>


Evaluate at all. Which makes absolutely no sense to me. Very frustrated ATM.

User avatar
Member
Member
vcarter - 1/27/2014 1:11:05 PM
   
RE:K# syntax help(solved)
Solved my issue by using placeholders. This transformation code generates a grid of spotlight elements of varying types. It also allows for a BusinessUnit parameter that filters news items. The only thing I am not sure of is if the OnInit is the proper way to set the where clause, otherwise I think this will work in a lot of instances.


<script runat="server">
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
if (this.Parent is IDataItemContainer)
{
IDataItemContainer cont = this.Parent as IDataItemContainer;
if (cont != null)
{
rLatestNews.WhereCondition = "selectedBusiness.val = '" + Eval("SpotlightBusinessUnit") + "'";
rLatestNews.ReloadData(true);
}else
{
Response.Write("Error: IDataItemContainer is null");
}
}
}

</script>


<%# ((DataItemIndex%3)==0)?"<tr>":"" %>
<asp:Placeholder runat="server" visible='<%# IfCompare(EvalInteger("SpotlightType"),1, false, true) %>' >
<td>
<img src="<%# Eval("SpotlightImage") %>" alt="" width="288" height="108" />
<h2><%# Eval("SpotlightTitle")%></h2>
<p><%# Eval("SpotlightText")%></p>
<a href="<%# Eval("SpotlightURL")%>" class="more">Learn More</a>
</td>
</asp:Placeholder>

<asp:Placeholder runat="server" visible='<%# IfCompare(EvalInteger("SpotlightType"),2, false, true) %>' >
<td>
<%# Eval("SpotlightCustomText")%>
<a href="<%# Eval("SpotlightURL")%>" class="more">Learn More</a>
</td>
</asp:Placeholder>

<asp:Placeholder runat="server" visible='<%# IfCompare(EvalInteger("SpotlightType"),3, false, true) %>' >
<td>
<h2>Latest News</h2>
<cms:queryrepeater StopProcessing="false" runat="server" ID="rLatestNews" QueryName="custom.news.FilterByBusinessAndRegion" TransformationName="custom.news.NewsLatestSetPath" TopN="5" OrderBy="NewsReleaseDate DESC" />
</td>
</asp:Placeholder>

<asp:Placeholder runat="server" visible='<%# IfCompare(EvalInteger("SpotlightType"),4, false, true) %>' >
<td rowspan="2">
<h2>Latest News</h2>
<cms:queryrepeater StopProcessing="false" runat="server" ID="rLatestNewsMulti" QueryName="custom.news.FilterByBusinessAndRegion" TransformationName="custom.news.NewsLatestSetPath" TopN="5" OrderBy="NewsReleaseDate DESC" />
</td>
</asp:Placeholder>


<%# ((DataItemIndex%3)==2) || (DataRowView.DataView.Count==(DataItemIndex+1))?"</tr>":"" %>


Thanks for everyone's help.