November Happy Hour will be moved to Thursday December 5th.

PageTree: Applying a class to the first item at the top level

Vote:
 

Hi

I am using a PageTree to display a submenu. I want to apply a class to the first item at the top level (i.e. the first item in the TopTemplate).

Can anyone advise me on how to achieve this?

Thanks,

Stuart

 

#42919
Sep 07, 2010 9:30
Vote:
 

If you can't find a way of doing it with the templates you can always do it by adding a databinding to a property which returns different data depending on whether it's called for the first time or not. Something like:

aspx:

.... <div class='normalclass <%#MyFlag ? String.Empty : "my_extra_class" %>'>...

codebehind:

protected bool MyFlag
{
get
{
bool oldFlag = _myFlag; // private field
_myFlag = true; // Flag that it's been hit
return oldFlag; // Returns false first time, then true for all additional times
}
}

It's probably a good thing to reset the flag in the OnDataBinding event or similar so you know it's state when databinding starts.

#42922
Sep 07, 2010 10:02
Vote:
 

You could also check the Container.ItemIndex.

#42941
Sep 07, 2010 13:55
* 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.