开发者

Dynamic ID's for HTML ELements

开发者 https://www.devze.com 2023-04-12 19:50 出处:网络
Lets say in an aspx page I have a for loop and within the for loop I want to createelements. How can I generate id \'s dynamically for them.

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++; %>
<% } %>
0

精彩评论

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

关注公众号