mdelvecchio
mdelvecchio

Reputation: 627

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') %>"

Upvotes: 0

Views: 1376

Answers (3)

Sam
Sam

Reputation: 2917

Also see this answer by me to one of the questions at SO for another way (using pure JavaScript's this object rather than using a custom property to get the clientID) of doing this.

Just thought of keeping these linked for future reference.

Upvotes: 0

Sam
Sam

Reputation: 2917

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.

Upvotes: 1

Diego Farina
Diego Farina

Reputation: 339

Try this to assign ID

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

Upvotes: 0

Related Questions