You were very close. This works, sort of :
<table>
<% for (int i = 1; i < 3; i++) { %>
<tr>
<td>Name: </td>
<td><asp:TextBox id="textName<%=i%>"/></td>
</tr>
<% } %>
</table>
If you view source, you'll see "textname1" and "textname2",
but that isn't very useful, is it ?
I say "sort of" because you can use this to repeat blocks of text,
with different font sizes, like the example in the QuickStart:
http://beta.asp.net/QUICKSTART/aspne...intro2_cs.aspx
but you cannot create controls with this type of code, because
as soon as you insert a second set of quotes into the line, i.e.,
<td><asp:TextBox id="textName<%=i%>" runat="server"/></td>
....the compiler will throw an exception.
So, you can use that type of code, to repeat any text,
IF you use only one set of quotes inside your brackets.
While <% %> code blocks provide a powerful way to custom manipulate
the text output returned from an ASP.NET page, they do not provide a
clean HTML programming model.
See :
http://beta.asp.net/QUICKSTART/util/...tro/intro3.src
As the sample above illustrates, developers using only <% %> code blocks
must custom manage page state between round trips and custom interpret posted values.
<%
This recommendation is from :
http://beta.asp.net/QUICKSTART/aspne...x#writingpages
%>
See intro2.aspx and intro3.aspx
Juan T. Llibre, ASP.NET MVP
ASP.NET FAQ :
http://asp.net.do/faq/
ASPNETFAQ.COM :
http://www.aspnetfaq.com/
Foros de ASP.NET en Español :
http://asp.net.do/foros/
======================================
"ºa¤Ö" <ºa¤Ö@¼ö¶l.¤½¥q> wrote in message news:uF**************@TK2MSFTNGP09.phx.gbl...
In tradition ASP, i can create a template like follow
<%
for i = 1 to 3
%>
<table>
<tr>
<td>Name: </td>
<td><input type="text" name="textName<%=i%>"/></td>
</tr>
</table>
<%
next
%>
But how to do it in ASP.net? I have tried using like this
<%
for (int i = 1; i < 3; i++) {%>
<table>
<tr>
<td>Name: </td>
<td><asp:TextBox id="textName<%#i%>"/></td>
</tr>
</table>
<%
} %>
but it not works....thanks