ItemCommand of Datagrid within a user control will not fire.

  • Thread starter Thread starter Li Zhang
  • Start date Start date
L

Li Zhang

I have a user control contain one datagrid. this datagrid contains one
button column with commandName "Review", I have event handler
datagrid_ItemCommand to handle this event and also wired the event when
initial. but when I put this user control in a web form, click the
review link(it is linkbutton) will not fire the event. Any one have any
idea what is the problem. Thanks a lot!
 
I would check the InitializeComponent method to see if the event handler for
this event is included.

--
David Lloyd
MCSD .NET
http://LemingtonConsulting.com

This response is supplied "as is" without any representations or warranties.


I have a user control contain one datagrid. this datagrid contains one
button column with commandName "Review", I have event handler
datagrid_ItemCommand to handle this event and also wired the event when
initial. but when I put this user control in a web form, click the
review link(it is linkbutton) will not fire the event. Any one have any
idea what is the problem. Thanks a lot!
 
Thanks David for your quick reply. I checked the InitializeComponent
method already. Here is the InitializeComponent method:

private void InitializeComponent()
{
this.imageDataGrid.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.imageDataGrid_ItemCommand);
this.Load += new System.EventHandler(this.Page_Load);
}

And I have my event handler:
private void imageDataGrid_ItemCommand(object sender,
DataGridCommandEventArgs e)
{
//some code here.
}

I don't know what is the problem. Thanks.
 
Li said:
Thanks David for your quick reply. I checked the InitializeComponent
method already. Here is the InitializeComponent method:

private void InitializeComponent()
{
this.imageDataGrid.ItemCommand += new
System.Web.UI.WebControls.DataGridCommandEventHandler(this.imageDataGrid_ItemCommand);

this.Load += new System.EventHandler(this.Page_Load);
}

And I have my event handler:
private void imageDataGrid_ItemCommand(object sender,
DataGridCommandEventArgs e)
{
//some code here.
}

I don't know what is the problem. Thanks.

I found my problem. I made a very stupid mistake. when page postback the
user control did not load at all. I should load this control in
Page_Load event not in an other event handler function. Thanks guys!
 
Back
Top