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

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

1 Answer 23 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Deepak Vasudevan
Top achievements
Rank 2
Deepak Vasudevan asked on 18 Nov 2011, 12:19 AM
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?

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Nov 2011, 11:51 AM
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
Tags
Grid
Asked by
Deepak Vasudevan
Top achievements
Rank 2
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or