The dynamically added button has to be re-added on postback during or before
the onLoad event.
What you likely have now is:
Create button "X"
User clicks button "X"
Page postbacks/reload
Page framework looks for button "X" but doesn't find it
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
"John Hughes" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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);
> }
>
>