This was pissing me off today. I had a datagrid that I needed to capture an OnItemCommand event for several controls in 1 to n number of DataGridItem objects. One of these controls in the datagrid was a UserControl that someone else created. It turns out, it is really not difficult, but I thought I'd share in case anyone else runs across having to figure this out.
public
class SeanControl :
System.Web.UI.UserControl
{
private
void
MyDropDown_SelectedIndexChanged(object
sender, System.EventArgs e)
{
if (this.SelectedIndexChanged
!= null)
{
this.SelectedIndexChanged(this,
EventArgs.Empty);
}
this.OnCommand(new
CommandEventArgs(String.Empty, e));
}
protected
virtual
void OnCommand(CommandEventArgs
e)
{
base.RaiseBubbleEvent(this,
e);
}
}
// Code in aspx page to handle datagrid ItemCommand...
private
void MyGrid_ItemCommand(object
source, DataGridCommandEventArgs e)
{
if(e.CommandSource
is SeanControl)
{
// Do stuff
}
}