Adding Button at runtime: Events not firing

J

John Hughes

Im adding a button at runtime but the DataGrid1.ItemCommand event does not
fire. I also have a button that I added at design time and this button does
fire the event ItemCommand.

Any ideas?

My Code :

private void InitializeComponent()
{
this.OpenPriceList.Click += new
System.Web.UI.ImageClickEventHandler(this.OpenPriceList_Click);
this.DataGrid1.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.DataGrid1_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);

}

private void OpenPriceList_Click(object sender,
System.Web.UI.ImageClickEventArgs e)
{
//Button on form which enables grid

ButtonColumn myColumn8 = new ButtonColumn();
myColumn8.Text="<IMG src=images/Info.gif border=0>";
myColumn8.ButtonType=ButtonColumnType.LinkButton;
myColumn8.CommandName="Select";
DataGrid1.Columns.Add(myColumn8);

DataGrid1.DataBind();
DataGrid1.Visible=true;
}

private void DataGrid1_ItemCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
Response.Write(e.Item.Cells[0].Text);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top