views:

33

answers:

0

In C#, I'm trying to figure out a way to use properties inside a templated usercontrol. Let me try to explain what I mean through an exmaple:

<example:myTreeOfItems runat="server">
    <HeaderTemplate>
        <div>
    </HeaderTemplate>

    <IndentStartTemplate>
        <ul>
    </IndentStartTemplate>

    <ItemHeaderDefaultTemplate>
        <li>
    </ItemHeaderDefaultTemplate>

    <ItemHeaderCertainDepthsTemplate Depth="2,4,5">
        <li class="special">
    </ItemHeaderCertainDepthsTemplate>

    <ItemTemplate>
        ... ... ...
    </ItemTemplate>

    <ItemFooterTemplate>
        </li>
    </ItemFooterTemplate>

    <IndentEndTemplate>
        </ul>
    </IndentEndTemplate>

    <FooterTemplate>
        </div>
    </FooterTemplate>
</example:myTreeOfItems>

How would one go about to achieve the functionality in this line?:

<ItemHeaderCertainDepthsTemplate Depth="2,4,5">

The idea is to use the Depth attribue so that the "2,4,5" string would be splitted on comma and casted to ints that would then control wether to use ItemHeaderCertainDepthsTemplate or ItemHeaderDefaultTemplate depending on the item index while populating the control from some collection.

The resulting output would look something like this:

<div>
    <ul>
        <li>Item 0</li>
        <li>Item 1</li>
        <li class="special">Item 2</li>
        <li>Item 3</li>
        <li class="special">Item 4</li>
        <li class="special">Item 5</li>
        <li>Item 6</li>
    </ul>
</div>

What would be the strategy to achieve this?