首先,我创建了一个动态表,并添加了一些文本框。
Dim tblRows As Integer = nos
Dim tblCols As Integer = 2
''# Create a Table and set its properties
Dim tbl As Table = New Table()
''# Add the table to the placeholder control
PlaceHolder1.Controls.Add(tbl)
''# Now iterate through the table and add your controls
For i As Integer = 0 To tblRows - 1
Dim tr As TableRow = New TableRow()
For j As Integer = 0 To tblCols - 1
Dim tc As TableCell = New TableCell()
Dim lbl As Label = New Label()
lbl.Text = "Student Name"
If j = 0 Then
tc.Controls.Add(lbl)
''# Add the TableCell to the TableRow
tr.Cells.Add(tc)
Else
Dim txtBox As TextBox = New TextBox()
''#txtBox.AutoPostBack = True
txtBox.ID = "aa" + i.ToString()
''#txtBox.ID = "TextBoxID" + (i + 1).ToString()
''#txtBox(i) = New TextBox
''# Add the control to the TableCell
tc.Controls.Add(txtBox)
''# Add the TableCell to the TableRow
tr.Cells.Add(tc)
End If
Next j
''# Add the TableRow to the Table
tbl.Rows.Add(tr)
Next i
Dim btn As Button = New Button()
btn.Text = "SUBMIT"
PlaceHolder1.Controls.Add(btn)
现在点击按钮我需要检索在各种文本框中输入的值并将其插入数据库。任何人都可以帮助我吗?
答案 0 :(得分:0)
尝试查看此页面:Insert TextBoxes into a Repeater dynamically and retrieve their value
很快,您可以在Page_Load方法上动态添加控件,并在Button1_Click方法中获取值。要按ID查找控件,可以使用FindControl方法。