This is a migrated thread and some comments may be shown as answers.

Image button in gridTemplateColumn does not fire click event

2 Answers 154 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bharanidharan
Top achievements
Rank 1
Bharanidharan asked on 24 May 2011, 12:15 AM
Hi,
I am creating a rad grid programatically with GridTemplateColumn. I have followed this link as guidance http://www.telerik.com/help/aspnet/grid/grdprogrammaticcreation.html ..I am using a image button in the MyTemplate : ITemplate. And the I am programatically creating new buttons based on a string array ..

Reassign =

 

new ImageButton();

Reassign.ID = Assignee;

Reassign.Click +=

 

new ImageClickEventHandler(Reassign_Click);

When i click on these buttons. the page just refreshes and the Event hander method Reassign_Click  is never called.
Please suggest me ways to fire this click event

 

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 25 May 2011, 11:19 AM
Hello Bharanidharan,

I have tried the same and that worked as expected at my end. Here I am pasting the the code (only relevant part). Please do a double check with it.
C#:
protected void Page_Init(object sender, EventArgs e)
    {
        RadGrid grid = new RadGrid();
 
        grid.ID = "RadGrid1";
        grid.MasterTableView.DataSourceID = "SqlDataSource1";
        grid.MasterTableView.DataKeyNames = new string[] { "ProductID" };
        grid.Skin = "Default";
        grid.PageSize = 10;
        grid.AllowPaging = true;
        grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
        grid.AutoGenerateColumns = false;
        grid.AllowFilteringByColumn = true;
 
        GridBoundColumn boundColumn = new GridBoundColumn();
        grid.MasterTableView.Columns.Add(boundColumn);
        boundColumn.DataField = "ProductID";
        boundColumn.HeaderText = "Product ID";
        boundColumn.UniqueName = "ProductID";
 
        NewTemplateColumn templateColumn = new NewTemplateColumn();
        templateColumn.ItemTemplate = new TemplateColumn();
        grid.MasterTableView.Columns.Add(templateColumn);
        templateColumn.DataField = "ProductName";
        templateColumn.HeaderText = "ProductName";
        templateColumn.UniqueName = "ProductName";
        ajaxPanel.Controls.Add(grid);
        grid.DataBind();
    }
public partial class TemplateColumn : ITemplate
   {
    public void InstantiateIn(Control container)
    {
        LiteralControl literalControl = new LiteralControl();
        literalControl.ID = "literalControl";
        literalControl.DataBinding += new EventHandler(literalControl_DataBinding);
        ImageButton btn = new ImageButton();
        btn.ID = "ImgBtn1";
        btn.Click += new ImageClickEventHandler(btn_Click);
        container.Controls.Add(btn);
    }
    void btn_Click(object sender, ImageClickEventArgs e)
    {
     
    }
  }

Thanks,
Shinu.
0
Bharanidharan
Top achievements
Rank 1
answered on 25 May 2011, 11:04 PM
Hi Shinu...

Thanks for the reply..
But the problem is as follows...
I'm creating controls in the prerender of a html table. and based on the datab that is bound to the column .. I am creating the buttons for each of comma separated value that is present in the datacolumn. For these buttons the events are not getting fired.


Tags
Grid
Asked by
Bharanidharan
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bharanidharan
Top achievements
Rank 1
Share this question
or