我在ASP.net上動態創建linkButton。當我點擊linkButton時,我需要幫助,它會將linkbutton名稱存儲到我的Label1(僅用於示例)。帶參數的LinkButton.OnClick方法
下面是代碼:
protected void Page_Load(object sender, EventArgs e)
{
for (int ctr = 0; ctr <= 2; ctr++)
{
LinkButton link = new LinkButton();
link.ID = "lnk" + ctr.ToString();
link.Text = "lnkName" + ctr.ToString();
link.Click += new EventHandler(DynamicClick);
this.form1.Controls.Add(link);
}
}
//when I click the buttonLink
public void DynamicClick(object sender, EventArgs e)
{
//label1.text will get the .text of the button that i pressed
Label1.Text = "";
}
感謝它的工作 –