RKh
RKh

Reputation: 14161

How to assign dynamic ID to label control inside DataList item template?

I have a DataList control which is bound by SQLDataSource. The data source is fetching two column values, viz: ID, Name.

The DataList ItemTemplate looks like this:

<DataList>
   <ItemTemplate>
       <asp:Label ID="Label1" runat="server" Text='<%# Eval(Name) %>' />
   </ItemTemplate>
</DataList>

I want the Label ID to be bound to the first column like:

<asp:Label ID='<%# Eval(ID) %> ...../>

But it gives error that ID should be simple.

Is there any way to use Eval value to generate assign to Label ID?

Upvotes: 1

Views: 2371

Answers (1)

andleer
andleer

Reputation: 22568

You can't assign it using data binding but you can access the ClientID and use that else were.

<label for='<%# Container.FindControl("TargetControlID").ClientID %>'>
    Label Text
</label>
<asp:Label ID="TargetControlID" runat="server" Text="Target Control" />

Upvotes: 2

Related Questions