2011-10-11 2 views
2

aspx 페이지에서 for 루프가 있고 for 루프 내에서 요소를 만들고 싶습니다. 어떻게 id를 동적으로 생성 할 수 있습니까? 예를 들어 HTML ELements에 대한 동적 ID

내가있는 경우 :

<div> 
    <% Foreach (item in itemCollection) { %> 
    { 
     <table> 
     <tr> 
     here I want to create td elements with id as reconText1 reconText2...the numbers at the end I get by incrementing the index. 

    </tr> 
    </table> 
    } 
</div> 

답변

3

당신은 foreach와 인덱스 또는 별도의 인덱스 변수와 for 루프를 사용할 수 있습니다

<% int i = 1; %> 
<% foreach (item in itemCollection) { %> 
    <tr> 
     <td id="reconText<%= i %>">...</td> 
    </tr> 
    <% i++; %> 
<% } %>