创建动态文本框的代码:
Protected Sub ddl_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs)
If ((Not (ddl.SelectedValue) Is Nothing) _
AndAlso (Integer.Parse(ViewState("count").ToString) <> 0)) Then
Dim i As Integer = 1
Do While (i <= Integer.Parse(ddl.SelectedValue))
Dim t As TextBox = New TextBox
t.ID = ("TextBox_" + i)
form1.Controls.Add(t)
i = (i + 1)
Loop
ElseIf ((Not (ddl.SelectedValue) Is Nothing) _
AndAlso (Integer.Parse(ViewState("count").ToString) > 0)) Then
Dim id As Integer = Integer.Parse(ViewState("count").ToString)
Dim i As Integer = 1
Do While (i <= Integer.Parse(ddl.SelectedValue))
Dim t As TextBox = New TextBox
t.ID = ("TextBox_" + id)
form1.Controls.Add(t)
id = (id + 1)
i = (i + 1)
Loop
End If
End Sub
并在页面加载中添加这个
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Not IsPostBack Then ViewState("count") = 0 End If End Sub
要验证数据,请在您的页面中添加一个按钮控件(我将很快添加代码)