开发者

ASP.NET ItemTemplate Container.DataItem

开发者 https://www.devze.com 2023-02-15 04:14 出处:网络
I have a Repeater on one of my pages like so: <asp:Repeater ID=\"rptrHalls\" runat=\"server\" OnItemCommand=\"Choose_Hall\">

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"
0

精彩评论

暂无评论...
验证码 换一张
取 消