这就是我在表单中的单元格中添加动态文本框的方式。
我希望使用其id从文本框中检索值并将其存储在字符串
中生成SQL查询
For i As Integer = 1 To nov
Dim tb As New TextBox()
Dim tb2 As New DropDownList
Dim tb3 As New TextBox()
Dim tr As New TableRow()
Dim tc As New TableCell()
Dim tc2 As New TableCell()
Dim tc3 As New TableCell()
tb.ID = "txtName" + i.ToString()
tb3.ID = "vv" + i.ToString()
tb2.ID = "dd" + i.ToString()
tb2.Items.Add("Int")
tb2.Items.Add("Varchar")
tb2.Items.Add("String")
tblMain.Rows.Add(tr)
tr.Cells.Add(tc)
tc.Controls.Add(tb)
tc2.Controls.Add(tb2)
tr.Cells.Add(tc2)
tc3.Controls.Add(tb3)
tr.Cells.Add(tc3)
Next
Button2.Visible = True
答案 0 :(得分:0)
您可以使用Page.FindControl方法:
“在页面命名容器中搜索具有指定标识符的服务器控件。”
e.g。
Dim t As TextBox= CType(Page.FindControl("txtName1"), TextBox)
答案 1 :(得分:0)
Dim str As String = DirectCast(Page.FindControl(“txtName”+ i),TextBox).Text
它无法在您的循环外访问,您必须使用您的代码进行管理。
答案 2 :(得分:0)
Sub TextControl()
Dim txt As New TextBox
txt.Text = ""
txt.Name = "txt" & Val(no)
txt.Size = New Size(44, 22)
txt.Text = m
txt.Location = New Point(tx, ty)
GroupBox2.Controls.Add(txt)
ty = ty + incr
no = Val(no) + 1
End Sub
Dim textBoxValue As String = CType(GroupBox2.Controls(txt.Name), TextBox).Text.Trim