[ASP.Net] Datagrid generic user control and DataGridCommandEventHandler

Discussion in 'ASP .Net Datagrid Control' started by sda, Jun 14, 2005.

  1. sda

    sda Guest

    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
     
    sda, Jun 14, 2005
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?U2hpanUgUG95aWxpbA==?=

    DataGridCommandEventHandler

    =?Utf-8?B?U2hpanUgUG95aWxpbA==?=, May 9, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    1,683
    David Lloyd
    May 9, 2005
  2. sda
    Replies:
    0
    Views:
    658
  3. Murat Tasan
    Replies:
    1
    Views:
    8,080
    Chaitanya
    Feb 3, 2009
  4. Replies:
    2
    Views:
    448
  5. MattB

    Dynamic Template firing DataGridCommandEventHandler

    MattB, Aug 24, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    121
    MattB
    Aug 24, 2004
Loading...

Share This Page