Dynamic ID's for HTML ELements
Lets say in an aspx page I have a for loop and within the for loop I want to create elements. How can I generate id 's dynamically for them.
For instance if I have :
<div>
<% Foreach (item in itemCollection) { %>
{
<table>
<tr>
here I want to create td elem开发者_JAVA技巧ents with id as reconText1 reconText2...the numbers at the end I get by incrementing the index.
</tr>
</table>
}
</div>
You could use a for
loop with index or a separate index variable with foreach
:
<% int i = 1; %>
<% foreach (item in itemCollection) { %>
<tr>
<td id="reconText<%= i %>">...</td>
</tr>
<% i++; %>
<% } %>
精彩评论