Dynamically Control event in RadGrid

4 posts, 0 answers
  1. lupotana
    lupotana avatar
    73 posts
    Member since:
    Nov 2006

    Posted 14 Nov 2011 Link to this post

    Good morning,
    I have a problem in the association of an event to a dynamically added control on the grid.

    The control is of type ImageButton.
    I insert this control in a column of type GridTemplateColumn.

    I used the method ItemCreated and / or ItemDataBound but neither of them solves my problem.

    This is the code (in ItemCreated and / or ItemDataBound)
    ImageButton btn = new ImageButton();
    btn.ToolTip = string.Format("{0} - {1}", split[4], split[1]);
    btn.ID = string.Concat(split[4], "_", split[0]);
    btn.ImageUrl = string.Format("~/Images/16x16/Phase/{0}.png", split[2]);
    btn.Click += new ImageClickEventHandler(ManageItem);                            
    ((GridDataItem)e.Item).Cells[codiceTiplogia + 4].Controls.Add(btn);

    The function is this :
    protected void ManageItem(object sender, ImageClickEventArgs e)

    This is the RadGrid..
    <telerik:RadGrid ID="gvPartite" runat="server" Skin="Office2010Blue" AutoGenerateColumns="false"
                        Visible="false" OnItemCreated="gvPartite_ItemCreated" OnItemDataBound="gvPartite_ItemDataBound">
                               <telerik:GridTemplateColumn ItemStyle-HorizontalAlign="Center" HeaderStyle-HorizontalAlign="Center"
                                        <asp:ImageButton ID="btnStatus" runat="server" OnClick="ManageItem" />
                                <telerik:GridTemplateColumn HeaderText="INFO" HeaderStyle-Font-Bold="true">
                                    <ItemTemplate> (personal code)
                                <telerik:GridTemplateColumn HeaderText="ARB" UniqueName="1">

    When I click on ImageButton i don't enter in the event...
    In this Grid there is another Imagebutton fixed...(you can see in RadGrid) btnStatus... This button is ok..

    I don't know Why...
    Idea ?

  2. Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 14 Nov 2011 Link to this post

    Hello lupotana,

    please try to do this thing with Button CommandName.

    btn.CommandName ="MyCommand";

    protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
                if (e.CommandName == "MyCommand")
                    // do your functionality here

    Jayesh Goyani
  3. Shaun
    Shaun avatar
    5 posts
    Member since:
    Jul 2012

    Posted 19 Feb 2013 Link to this post


    I have pretty much the same problem but I have a DatePicker and a TimePicker and I need the Event to trigger when the Time and Date is changed.

    Is there any way to do that
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Feb 2013 Link to this post


    Try the following code.
    void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
            if (e.Item is GridDataItem)
                GridDataItem item = e.Item as GridDataItem;
                RadDatePicker pkr = (RadDatePicker)item.FindControl("RadDatePicker1");
                pkr.AutoPostBack = true;
                pkr.SelectedDateChanged += new Telerik.Web.UI.Calendar.SelectedDateChangedEventHandler(pkr_SelectedDateChanged);
     void pkr_SelectedDateChanged(object sender, Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs e)

Back to Top