try this code may be it will help u :
View:
<asp:DropDownList ID="DropDownNoOfUsers" runat="server" AutoPostBack="True">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem>5</asp:ListItem>
</asp:DropDownList>
<br />
<asp:Panel ID="pnldisplayform" runat="server">
</asp:Panel>
<asp:Button runat="server" ID="Btn_Value" OnClick="Btn_Value_Click" Text="GetValue"/>
<br />
<asp:ListBox ID="ListUser" runat="server" Width="200"></asp:ListBox>
Code Behind :
private List<string> _users;
protected void Page_Load(object sender, EventArgs e)
{
var cnt = Int32.Parse(DropDownNoOfUsers.SelectedValue);
Users(cnt);
}
public void Users(int cnt)
{
for (var i = 1; i <= cnt; i++)
{
var txtuserAlias = new TextBox { Text = "", ID = "txtUserAlias" + i };
txtuserAlias.Attributes.Add("runat", "Server");
txtuserAlias.EnableViewState = true;
pnldisplayform.Controls.Add(txtuserAlias);
}
}
public List<string> GetUsers()
{
return pnldisplayform.Controls.OfType<TextBox>().Select(box => box.Text).ToList();
}
protected void Btn_Value_Click(object sender, EventArgs e)
{
_users = GetUsers();
foreach (var user in _users)
{
ListUser.Items.Add(user);
}
}