So, this screams as being homework… Regardless you need to set up a counter when you go through your Product List. Showing all of your code will likely help with questions in the future.
List<string> ProductList = new List<string>();
int i;
I assume that your list and variables are not being shown. And having the code in the page load helps too.
protected void Page_Load(object sender, EventArgs e)
{
ProductList.Add("Milk");
ProductList.Add("Food");
ProductList.Add("Cooked");
ProductList.Add("Beef");
foreach (string product in ProductList)
{
Button button = new Button();
button.ID = this.ProductList[i].ToString();
button.Text = this.ProductList[i].ToString();
//button.Attributes["src"] = "trash.png";
place.Controls.Add(button);
i++;
}
}
CLICK HERE to find out more related problems solutions.