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

Persisting state of checkboxes in GridTemplateColumns

1 Answer 71 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Hunter
Top achievements
Rank 1
Hunter asked on 16 Sep 2013, 05:11 PM
When I was using a GridClientSelectColumn to select rows in my RadGrid, I used this post and this post to persist the checked state on the client side, using JavaScript to store the selected row ids in a hidden field.

I'd like to do this with checkboxes that are GridTemplateColumns defined on the server side, like this:

    foreach (blah blah)
    {
        templateColumn = new GridTemplateColumn();
        RadGrid1.MasterTableView.Columns.Add(templateColumn);
        templateColumn.ItemTemplate = new MyTemplate(blah);
        templateColumn.HeaderText = blah;
    }
 
private class MyTemplate : ITemplate
{
    protected CheckBox chk;
    private string columnName;
 
    public MyTemplate(string columnName)
    {
        this.columnName = columnName;
    }
 
    public void InstantiateIn(Control container)
    {
        chk = new CheckBox();
        chk.ID = "chk" + columnName;
        chk.DataBinding += new EventHandler(DataBinding);
        chk.Enabled = true;
        container.Controls.Add(chk);
    }
 
    void DataBinding(object sender, EventArgs e)
    {
        CheckBox cBox = (CheckBox)sender;
        GridDataItem container = (GridDataItem)cBox.NamingContainer;
        cBox.Checked = (bool)((DataRowView)container.DataItem)[columnName];
    }
}

I think I can do the same kind of thing here, except I can no longer call the JavaScript function RadGrid1_RowSelected since I'm not selecting the row, just checking boxes. I'll need to use another event that fires when a checkbox is checked or unchecked (I guess that's CheckChanged). But how do I add a handler on the server side and have it handled on the client side?

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 19 Sep 2013, 01:47 PM
Hi Hunter,

I have already answered you support ticket and I would ask you to continue our conversation there if any further assistance is needed.

Regards,
Kostadin
Telerik
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to the blog feed now.
Tags
Grid
Asked by
Hunter
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or