2013-11-23 57 views
1

添加複選框在這個代碼片段我試圖從源視圖動態在asp.net VB從源視圖

<table width="100%" cellpadding="0" cellspacing="0"> 
    <% 
     Dim y As Integer = 1 
     Dim name1 As String = "" 
     For i As Integer = 1 To 5 
    %> 
    <tr> 
     <% 
      For j As Integer = 1 To 10 
      name1 = "l1A" + y.ToString 
     %> 
      <td style="padding-top:3px; padding-bottom:3px"> 
      <label><asp:CheckBox ID="<%=name1%>" runat="server" onclick="return 
        calculate(this.id, 1)" /><span class="overlay" ></span></label> 

      </td> 
     <% 
      y = y + 1 
      Next 
     %> 
    </tr> 
    <% 
     Next 
     %> 
</table> 

使50複選框動態現在的問題是,...

由於我試圖給動態名稱的複選框,這樣我可以從後端檢查,但在ID="<%=name1%>"

其示值誤差告訴我怎麼解決這個問題

+1

它會顯示什麼錯誤? – Marco

+0

將'ID =「<%=name1%>」'更改爲'ID ='<%=name1%>''。 – afzalulh

+0

你有沒有試過我的答案? –

回答

0

你可以試試這個:

<table width="100%" cellpadding="0" cellspacing="0"> 
    <% 
     Dim y As Integer = 1 
     Dim name1 As String = "" 
     For i As Integer = 1 To 5 
    %> 
    <tr> 
     <% 
      For j As Integer = 1 To 10 
      name1 = "l1A" + y.ToString 
     %> 
      <td style="padding-top:3px; padding-bottom:3px"> 
      <label><input type="checkbox" id="<%=name1%>" onclick="return calculate(this.id, 1)"/><span class="overlay" ></span></label> 

      </td> 
     <% 
      y = y + 1 
      Next 
     %> 
    </tr> 
    <% 
     Next 
     %> 
</table>