[ASP.Net] Datagrid generic user control and DataGridCommandEventHandler

S

sda

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)
ListDataGridDataBind();
}

2/ My Datagrid has a programmatically defined template column with
ImageButton

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);
container.Controls.Add(ib);
}
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.DataItem, _sId));
ib.CommandName = Convert.ToString(DataBinder.Eval(container.DataItem,
_sColumnName));
ib.ImageUrl = Convert.ToString(DataBinder.Eval(container.DataItem,
_sColumnName));
}
}

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_ListDataGridImageCommand);
ucListDataGrid.ListDataGridDataBind();

and

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 ?

Thanks

Best regards
SDA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top