我正在 c# 中生成动态链接按钮。单击其中任何一个时,将调用另一个函数,该函数将显示单击了哪个链接按钮。但单击任何链接按钮时都不会调用它。
这就是我生成它的方式。
Int32 i; //create a integer variable
for (i = 1; i <= 10; i++) // will generate 10 LinkButton
{
LinkButton lb = new LinkButton(); //create instance of LinkButton
lb.Text = Convert.ToString(i) + ""; //LinkButton Text
lb.ID = Convert.ToString(i); // LinkButton ID’s
lb.CommandArgument = Convert.ToString(i); // LinkButton CommandArgument
lb.CommandName = Convert.ToString(i); // LinkButton CommanName
lb.OnClientClick+= new CommandEventHandler(lb_Command); //Create Handler for it.
//type lb.Command += and press double time Tab Key it will generat the lb_Command() code
PlaceHolder1.Controls.Add(lb); // Adding the LinkButton in PlaceHolder
}
这是功能代码。
void lb_Command(object sender, CommandEventArgs e)
{
Label1.Text = e.CommandName; // will display the which Linkbutton clicked
Label1.Text = "aaaa";
// Response.Redirect(“LnkBtn.aspx?val=” + Label1.Text); // you can also use as QueryString to send values to another page
}
请提供帮助。
谢谢。