ASP.NET ItemTemplate Container.DataItem
I have a Repeater on one of my pages like so:
<asp:Repeater ID="rptrHalls" runat="server" OnItemCommand="Choose_Hall">
<ItemTemplate>
<asp:Button ID="btn<% Container.DataItem %开发者_如何学JAVA>" runat="server"
CommandName="<% Container.DataItem %>" Text="<% Container.DataItem %>"
/>
</ItemTemplate>
</asp:Repeater>
But, when I run it it errors out with the message:
'btn<% Container.DataItem %>' is not a valid identifier.
I want to append btn to the Container.DataItem value so that I have dynamically assigned control names that are associated with the underlying data item. Any ideas?
It should be something like
<asp:Button ID='<%# "btn" + Container.DataItem %>' runat="server"
and depends on the type of Container.DataItem
but is there a reason why you want to set the ID and not use something like this ?
<asp:Button ID="btnSubmit" runat="server"
精彩评论