问题描述
我的c#中有一个productList,我想为productList中的每个产品创建一个按钮...这里是c#
foreach(string product in ProductList)
{
Button button = new Button();
button.ID = "blah";
button.Text = "hi";
//button.Attributes["src"] = "trash.png";
button.Click += new EventHandler(button_click);
place.Controls.Add(button);
}
private void button_click(object sender,EventArgs e)
{
throw new NotImplementedException();
}
这是HTML
<asp:PlaceHolder runat="server" ID="place" /><br />
我不明白为什么按钮未显示在网页上。顺便说一句,这是MVC .net网页,以防万一您还没有得到它
请帮助:)
解决方法
因此,这听起来像是功课……无论您在浏览产品列表时都需要设置一个计数器。显示您的所有代码将来可能会帮助您解决问题。
viewForAnnotation
我认为您的列表和变量未显示。而且在页面加载中包含代码也有帮助。
List<string> ProductList = new List<string>();
int i;