Repeater或者DataList中如果要使用Custom User Control可以使用如下方法。
<asp:Repeater ID="repeater1" runat="server">
<ItemTemplate>
<tr>
<td><uc1:mycontrol runat="server" id="mycontrol1" ProductID='<%# DataBinder.Eval(Container.DataItem, "Key") %>' /></td>
</tr>
</ItemTemplate>
</asp:Repeater>
注意,如果 '<%# ... %>' 没有用单引号而用双引号,服务器会发出The server tag is not well formed的错误。
<asp:Repeater ID="repeater1" runat="server">
<ItemTemplate>
<tr>
<td><uc1:mycontrol runat="server" id="mycontrol1" ProductID='<%# DataBinder.Eval(Container.DataItem, "Key") %>' /></td>
</tr>
</ItemTemplate>
</asp:Repeater>注意,如果 '<%# ... %>' 没有用单引号而用双引号,服务器会发出The server tag is not well formed的错误。

本文介绍如何在ASP.NET的Repeater或DataList控件中使用自定义用户控件(CustomUserControl),并提供了具体的实现代码示例。特别强调了在设置属性时正确使用单引号的重要性。
3242

被折叠的 条评论
为什么被折叠?



