Telerik Bug with Dynamic Checkbox in ItemTemplateColumn seems to be having an issue with Postback

2 posts, 0 answers
  1. Deepak Vasudevan
    Deepak Vasudevan avatar
    82 posts
    Member since:
    May 2010

    Posted 17 Nov 2011 Link to this post

    I am having a GridTemplateColumn with a checkbox that is  being dynamically created. I  need to have this checkbox with an ability to AUTOPOSTBACK but the autopostback event never seems to fire. The browser does not fire the event consistently and also even when it fires the event handler is never reached.

    Looks like it is a bug in Telerik RadGrid as this post http://www.telerik.com/community/forums/aspnet-ajax/grid/grid-with-dynamic-columns-gridtemplatecolumn-dynamic-control-events-not-firing.aspx shows.

    Is there a workaround or fix for the same?
  2. Jayesh Goyani
    Jayesh Goyani avatar
    2732 posts
    Member since:
    May 2010

    Posted 18 Nov 2011 Link to this post

    Hello,

    There is not any such type of issue with Radgrid please check below code snippet.
    public class MyTemplate : System.Web.UI.Page, ITemplate
    {
        protected CheckBox boolValue;
     
        private string colname;
     
        public MyTemplate(string cName)
        {
            colname = cName;
        }
     
        public void InstantiateIn(System.Web.UI.Control container)
        {
            boolValue = new CheckBox();
            boolValue.ID = "boolValue";
            boolValue.AutoPostBack = true;
            container.Controls.Add(boolValue);
        }
    }
      protected void Page_Load(object sender, EventArgs e)
        {
     
            RadGrid RadGrid5 = new RadGrid();
            RadGrid5.ID = "RadGrid5";
            RadGrid5.AutoGenerateColumns = false;
     
            GridTemplateColumn templateColumn = new GridTemplateColumn();
            string templateColumnName = "ContactName";
            templateColumn.ItemTemplate = new MyTemplate(templateColumnName);
            templateColumn.HeaderText = templateColumnName;
            RadGrid5.MasterTableView.Columns.Add(templateColumn);
            RadGrid5.ItemDataBound += new GridItemEventHandler(RadGrid5_ItemDataBound);
            dynamic data = new[] {
                    new { CustomerId = 1, CustomerName = 2,Bool = true},
                    new { CustomerId = 4, CustomerName = 5,Bool = false}
                    
                };
            RadGrid5.DataSource = data;
            RadGrid5.DataBind();
            this.Form.Controls.Add(RadGrid5);
     
           
    }
     
     
     void RadGrid5_ItemDataBound(object sender, GridItemEventArgs e)
        {
            if (e.Item is GridDataItem)
            {
                GridDataItem item = e.Item as GridDataItem;
     
                CheckBox boolValue = item.FindControl("boolValue") as CheckBox;
                boolValue.CheckedChanged += new EventHandler(boolValue_CheckedChanged);
            }
        }
     
        void boolValue_CheckedChanged(object sender, EventArgs e)
        {
            Response.Write((sender as CheckBox).Checked.ToString());
        }

    Let me know if any concern.

    Thanks,
    Jayesh Goyani
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top