Here is how you create a Button with Command event.
Once it is created, you need to find a way of displaying it. The following example uses PlaceHolder
; you can also substitute with Panel
if you want.
ASPX
<asp:PlaceHolder runat="server" ID="PlaceHolder1"></asp:PlaceHolder>
Code Behind
protected void Page_Load(object sender, EventArgs e)
{
for (int i = 0; i < 5; i++)
{
var button = new Button
{
ID = "Button" + i,
CommandArgument = i.ToString(),
Text = "Submit" + i
};
button.Command += Load_Items;
PlaceHolder1.Controls.Add(button);
}
}
private void Load_Items(object sender, CommandEventArgs e)
{
int id = Convert.ToInt32(e.CommandArgument);
// Do something with id
}