rory
rory

Reputation: 1438

Access web part properties from within CMSRepeater Template

Is there any way I can access a webpart's properties from withing a repeater's template (or vice versa)?

<div ID="RepeaterWrapper" runat="server">
    <cms:CMSRepeater ID="repItems" runat="server">
        <ItemTemplate>
            <div class="col-sm-4">
                <!-- I want to access this div in my code behind or else have it access a property from the code behind-->
            </div>
        </ItemTemplate>
    </cms:CMSRepeater>
</div>

I want to set the inner div's bg color and I can't use classes as the property is given as a hexadecimal color so it would mean a few thousand classes!

Worst case scenario I can do it with some js but would rather a "purer" way of doing it if it exists.

Thanks in advance

Upvotes: 0

Views: 129

Answers (3)

Brenden Kehren
Brenden Kehren

Reputation: 6117

Assuming your datasource has that background color in the returned data, once you bind your datasource to the repeater you have access to that within the item templates. Simply use something like this:

<div class="col-sm-4 <%# Eval("BgColorColumnName") %>">

Now if you want to set a value from the actual webpart itself, you need to make sure the property is a public property then you can use something like:

<div class="col-sm-4 <%# YourPublicPropertyName %>">

Upvotes: 2

Trevor F
Trevor F

Reputation: 1437

If this was in portal method you could grab the XML from the Page Template table and get values from it. Since it's purely from code, and it's a repeater, usually you need to store the data somewhere outside the repeater itself (in the items you repeat, or in the current page form data).

If you can access it anywhere from a Macro, then you can use the CMS.MacroEngine.MacroContext.Current.ResolveMacro() to resolve that and get the value.

Can you give us a little more info on where the div BG color would be stored? why it has to be in the repeater itself?

Upvotes: 0

Zach Perry
Zach Perry

Reputation: 756

Are all the items going to have the same color? If its per item, then modify the items you are pulling to include the value.

Upvotes: 0

Related Questions