the important thing is to recreate those controls upon postback, so it is important to do it in Page_Load or before, for example,
void Page_Load(Object sender, EventArgs e)
{
//get data from the database
int nCount = ..; //might need to save nCount inside a ViewState or Session variable
for (int i=0; i < nCount; i++)
{
ListBox lb = new ListBox();
lb.ID = "lb" + i.ToString();
lb.SelectedIndexChanged += new EventHandler(YourHandler);
form1.Controls.Add(lb);
if (!IsPostBack) //or the first time you create them
{
lb.DataSource = ...;
...
lb.DataBind();
}
}