ASP.NET:向表格单元格添加复选框

时间:2013-02-17 20:50:49

标签: asp.net vb.net server-side

这是我的表:

<asp:Table ID="Table1" runat="server">
    <asp:TableRow>
        <asp:TableCell>number</asp:TableCell>
        <asp:TableCell ID="webCell"></asp:TableCell>
    </asp:TableRow>
</asp:Table>

这是我的服务器端代码:

For i = 0 To IDsList.Length - 1
    Dim chk As CheckBox = New CheckBox()
    chk.ID = "webCatID" & Convert.ToString(i)
    chk.Text = Convert.ToString(CatsName(i))
    chk.BorderStyle = BorderStyle.None
    chk.CssClass = "checkBox"
    webCell.Controls.Add(chk) 'does not work, it does not webCell
Next

如何将这些复选框添加到该单元格?

1 个答案:

答案 0 :(得分:1)

WebCell不是runat=server,因此您无法在代码隐藏中引用它,添加它:

<asp:TableCell ID="webCell" runat="server"></asp:TableCell>