Creating Buttons at Runtime from Data?
I am trying to create a series of buttons based on row data from a database at runtime, currently I use a panel and add a new button each go around in a loop. However I do not know how to create a dynamic method for each new button click....also there is no way to control the spacing in the panel so all the buttons jumble together. Does anyone have a better way to create these buttons Or a way of making a onclick event for each button

Creating Buttons at Runtime from Data?
OliverKofoed
But, in ASP.NET, you should create those buttons in Page_Init, not on Page_Load, to avoid ViewState issues...
In ther words those dynamic buttons should be created BEFORE the ViewState values are regenerated from the request. Or you will end up with ViewState corruptions, and it wont work. :) For your own safety, as they say...
After creating the button you can add a handler to the click event like :
btn.Click += new EventHandler(this.Button_Click);
you should also have a method like below on the form :
private void Button_Click(object sender, EventArgs e)
{
// to do: Add your code
}