dynamiske knapper igen
Mit problem er at jeg gerne vil lave dynamiske events uden for Page_Load. Jeg spurgte til det i et tidligere indlæg og fik svar, men min hjerne kunne ikke helt forstå det alligevel.Har følgende kode... nogen som kan forklare mig hvad jeg skal gøre for at fange events på de "dynamiske" knapper. :
aspx start_______________________________________
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="DropDownList1" style="Z-INDEX: 101; LEFT: 321px; POSITION: absolute; TOP: 189px"
runat="server" AutoPostBack="True">
<asp:ListItem Value="0">Ingenting</asp:ListItem>
<asp:ListItem Value="1">noget</asp:ListItem>
</asp:DropDownList>
<asp:Panel id="Panel1" style="Z-INDEX: 102; LEFT: 444px; POSITION: absolute; TOP: 304px" runat="server">Panel</asp:Panel>
</form>
aspx slut_______________________________________
cs start_______________________________________
public class testevent : System.Web.UI.Page
{
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.DropDownList DropDownList1;
private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
}
#region Web Form Designer generated code
override protected void OnInit(EventArgs e)
{
//
// CODEGEN: This call is required by the ASP.NET Web Form Designer.
//
InitializeComponent();
base.OnInit(e);
}
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.DropDownList1.SelectedIndexChanged += new System.EventHandler(this.DropDownList1_SelectedIndexChanged);
this.Load += new System.EventHandler(this.Page_Load);
}
#endregion
private void DropDownList1_SelectedIndexChanged(object sender, System.EventArgs e)
{
mineKnapper();
}
public void mineKnapper()
{
int x = 6;
for (int i = 0;i<=x;i++)
{
LinkButton myBut = new LinkButton();
myBut.ID = ""+i;
myBut.Text = "knap nr "+i;
myBut.CommandName = "navn = "+i;
myBut.Command +=new CommandEventHandler(myBut_Command);
Panel1.Controls.Add(myBut);
}
}
private void myBut_Command(object sender, CommandEventArgs e)
{
Response.Write(e.CommandName.ToString());
}
}
cs slut_______________________________________
???
På forhånd takker..