Try our conversational search powered by Generative AI!

PageTree with if and #

I would like to do something like this but since I can't use if in combination with # I'm lost... Does anyone know how to come around this? /Stefan <%#if(container.haschildren && container.currentpage.indent="=" 3) { %> <% } else { %> "> <%#container.currentpage.pagename%> (B:<%#container.currentpage.indent%>) <% } %> And so on...
Apr 05, 2005 15:01
The problem with the # expression is that the expression must always return a string. Also, the expression is not allowed to modify the parent's control collection. But as long as you follow these rules you can do pretty much anything. For example: <%# "Some bold text here" %> Here I just added a element including some text, but from ASPNET's point of view it is only text and does not affect the parent's control collection. Using the same principle you could do this: <%# GetSomeValue(Container) %> and in code-behind: protected string GetSomeValue( PageTemplateContainer container) { // do whatever... return "

Some HTML here

"; }
You can access the current item's values using the container parameter (container.CurrentPage gets the actual page, for example) and you can generate and return whatever HTML you need in the function. Just a disclaimer... There are more ways to solve this problem. The above technique is easy to use but a bit ugly, since it generates HTML on the fly without using controls and collections. But it gets the job done. You can also add all controls to the page and use the Visible property to decide which controls should actually get rendered (controls whos Visible property is false never get rendered). For example: The Visible property expects true/false, so the functions above should return booleans.
Apr 06, 2005 17:21
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.