J
John Hughes
Im adding a button at runtime to a datagrid 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);
}
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);
}