我试图使用数据集中的一些数据动态添加输入复选框类型和asp文本框到Asp表格单元格。我已经阅读了几篇关于这方面的文章,但没有一篇希望达到。将动态用户控件添加到Asp表格
这是我使用的代码(如果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)和其他一些combins,但结果仍然相同。将控件添加到单元格会使复选框(以及任何早期定义的内容)消失。
谢谢大家。
如果你用'Repeater'做了这个,你的生活会容易得多。如果您想探索此选项,请告知我,我很乐意为您举个例子。 – 2013-03-04 17:12:29