Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > [ASP.Net] Datagrid generic user control and DataGridCommandEventHandler

Thread Tools

[ASP.Net] Datagrid generic user control and DataGridCommandEventHandler

Posts: n/a
Hi everybody,

I have a problem to fire an event in a DataGrid.

1/ I have got a datagrid in a generic user control

protected System.Web.UI.WebControls.DataGrid dgListDataGrid;

public void ListDataGridDataBind()
.... my databind function
private void Page_Load(object sender, System.EventArgs e)
if (!IsPostBack)

2/ My Datagrid has a programmatically defined template column with

class myModifyTemplateColumn : ITemplate
string _sColumnName = "";
string _sId = "";
//public event DataGridCommandEventHandler myImageCommand;

public myModifyTemplateColumn(string sColumnName, string sId)
_sColumnName = sColumnName;
_sId = sId;
public void InstantiateIn(Control container)
ImageButton ib = new ImageButton();
ib.DataBinding += new EventHandler(this.BindImageButtonColumn);
public void BindImageButtonColumn(object sender, System.EventArgs e)
ImageButton ib = (ImageButton) sender;
DataGridItem container = (DataGridItem) ib.NamingContainer;
ib.ID = _sColumnName + _sId;
ib.EnableViewState = true;
ib.CausesValidation = false;
ib.CommandArgument =
Convert.ToString(DataBinder.Eval(container.DataIte m, _sId));
ib.CommandName = Convert.ToString(DataBinder.Eval(container.DataIte m,
ib.ImageUrl = Convert.ToString(DataBinder.Eval(container.DataIte m,

3/ My Generic User Control contain a public event :

public event DataGridCommandEventHandler ListDataGridCommand;

4/ My Generic User Control in the Page_Init create the new event :

this.dgListDataGrid.ItemCommand += this.ListDataGridCommand; //
(dgListDataGrid : the grid)

5/ I use this datagrid in several others user controls
In ascx :

<uc1:ListDataGrid id="ucListDataGrid" runat="server"></uc1:ListDataGrid>

In ascx.cs :

ucListDataGrid.ListDataGridDataSource = oMain.Service.ListeDesEtapes();
ucListDataGrid.ListDataGridCommand += new
DataGridCommandEventHandler(ucListDataGrid_ListDat aGridImageCommand);


private void ucListDataGrid_ListDataGridImageCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
Response.Write("Fire : ucListDataGrid_ListDataGridImageCommand");

Never my ImageButton event is fired !!!
Any suggestions ?


Best regards

Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
User Control to Control Other User Control Jonathan Wood ASP .Net 4 02-02-2010 03:41 PM
persisting changes to a control outside a user control from the user control? Mad Scientist Jr ASP .Net 0 03-22-2006 08:02 AM
[ASP.Net] Datagrid generic user control and DataGridCommandEventHandler sda ASP .Net 0 06-14-2005 03:19 PM
DataGridCommandEventHandler =?Utf-8?B?U2hpanUgUG95aWxpbA==?= ASP .Net 1 05-09-2005 12:51 PM
Dynamic Template firing DataGridCommandEventHandler MattB ASP .Net Datagrid Control 0 08-24-2004 03:37 PM