Search code examples
asp.netrepeater

Repeater: databind server-side ID in item control?


When binding a datasource to a Repeater control, is it possible to databind to the ID property of a server-side control inside the ItemTemplate? like so:

<asp:Repeater ID="rptToolTips" runat="server">
    <ItemTemplate>

        <telerik:RadToolTip ID="tt<%# Eval("Name") %>" ClientIDMode="Static" runat="server">
            <div class="tip">
                <div class="segName">Segment #<%# Eval("Name") %></div>
                <div>Flow:<%# Eval("Flow", "{0:N}") %></div>
            </div>
        </telerik:RadToolTip>

    </ItemTemplate>     
</asp:Repeater>

...here I'm trying to set the RadToolTip's ID property to "tt[name-value]". I've tried a few variants but they're invalid:

ID="tt<%# Eval("Name") %>"

ID='tt<%# Eval("Name") %>'

ID="tt<%# Eval('Name') %>"

Solution

  • It's not possible. A server control's ID is set at the time it's being created or at design time. Once it's set you cannot reset it during the data binding.

    But, if you are trying to use this ID value in JQuery or JavaScript you could employ the following hack.

    Add a custom property to your control (give it any name you like and in this case I'll use myId)

    myId='<%# Eval("Name") %>'
    

    No you can find this element by this myId property

    Hope this helps.