【发布时间】:2013-03-04 15:58:36
【问题描述】:
我正在尝试使用数据集中的一些数据将 输入复选框类型 和 asp 文本框 动态添加到 Asp Tablecell。我已经阅读了一些关于此的帖子,但没有一个想要达到的组合。
这是我正在使用的代码(其中 ds 是数据集,tblMeasuredChar 是 Asp 表):
If ds.Tables(0).Rows.Count > 0 Then
For Each dr As DataRow In ds.Tables(0).Rows
Dim tr As New TableRow()
'defining input
Dim tc As New TableCell()
tc.Text = "<input type=" & Chr(34) & "checkbox" & Chr(34) & " name=" & Chr(34) & "chkMeasuredChars" & Chr(34) & " value=" & Chr(34) & dr("id") & Chr(34) & "/>" & dr("description")
'defining unique textbox
Dim txtbx As New TextBox()
txtbx.ID = "tbMeasuredChars" & dr("id")
'add it to the cell
tc.Controls.Add(txtbx)
'add the cell to the row
tr.Controls.Add(tc)
tblMeasuredChar.Rows.Add(tr)
Next
End If
问题是只显示了我添加到 TableRow 的最后一个“东西”。我必须使用这种类型的输入,不可能使用一些 asp 复选框。是否可以将用户控件添加到已经有其他文本的 TableCell 中?
我已经尝试添加 TableCell 像 tr.Cells.Add(tc) 和其他一些组合,但结果仍然相同。将控件添加到单元格会使复选框(以及早期定义的所有内容)消失。
谢谢大家。
【问题讨论】:
-
如果您使用
Repeater进行此操作,您的生活会轻松很多。如果您想探索此选项,请告诉我,我很乐意为您举个例子。
标签: asp.net vb.net user-controls celltable