close
1.先在頁面新增Panel 控制項
2.於Page_Load中
Button[] btn = new Button[4]; //設定Button數
//利用 Controls.Add 新增
for (int i = 0; i < btn.Length; i++)
{
btn[i] = new Button();
btn[i].ID = "btn" + i.ToString();
btn[i].Text = i.ToString();
btn[i].Height = 25;
btn[i].Width = 70;
btn[i].Click += new EventHandler(btn_Click);
Pdl.Controls.Add(btn[i]);
}
3.新增Click event
protected void btn_Click(object sender, EventArgs e)
{
Button temp = (Button)sender;
Response.Write(temp.ID);
}
文章標籤
全站熱搜
留言列表