รายละเอียดของการตอบ ::
ผมเข้าใจว่า code มันน่าจะเป็นแบบนี้หรือเปล่าครับ
1.แต่พอเลือก 1 มันขึ้นมา 2 เลือก 2 มันขึ้นมา 4 ซะอย่างนั้น
2.เราสามารถกำหนดชื่อมันได้ไหม
With txtBox
.Text = "My Customer"
.Font.Size = "30"
.Name = "txtboxname" & i ????? ลองดูแล้วมันเหมือนไม่รู้จัก .name
End With
Code
<form id="form1" runat="server">
<asp:Panel id="pnlMain1" runat="server"></asp:Panel><br />
<asp:DropDownList id="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
<asp:ListItem Value="0" Selected="True">- Please select item</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
</asp:DropDownList>
</form>
..........................
Code
Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim i As Integer
Dim txtBox As TextBox
For i = 1 To CInt(DropDownList1.SelectedItem.Value)
txtBox = New TextBox
With txtBox
.Text = "My Customer"
.Font.Size = "30"
End With
Me.pnlMain1.Controls.Add(txtBox)
Next
End Sub