ASP.NET动态创建和放大器;设置不同的ID为相同的控制 [英] ASP.NET Dynamically creating & setting different ID for the same controls

查看:157
本文介绍了ASP.NET动态创建和放大器;设置不同的ID为相同的控制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是有可能使相同的控制与不同的ID属性?

is it possible to render the same controls with different ID property ?

<%for (int i = 0; i < 15; i++)
  {%>
     <asp:Label ID='Label<%=i.ToString() %>' runat="server"/>
<%}%>

下面是错误的:标签和LT;%= i.ToString()%>'不是一个有效的标识符

推荐答案

是的,这是可能的,但由code behined,不是WebForms的加价。从WebForm的加价就可以在循环仅添加HTML的控制,而不是asp.net控制。

Yes, it is possible but from code behined, not WebForms mark-up. From WebForm mark-up you can add only "html" controls in loop, not "asp.net" controls.

从code的后面,你可以做:

From code behind you can do:

for( int i=0;i<15;i++)
{
    var l = new Label();
    Label.ID = "Label" + i;
    Controls.Add(l);
}

这篇关于ASP.NET动态创建和放大器;设置不同的ID为相同的控制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆