Pages

Wednesday, December 28, 2011

How to handle RadGrid's Select Column Checkbox Event


Do these steps to handle the Radgrid's select column checkbox event.

1. Allow row selection

<ClientSettings ...>
                        <Selecting AllowRowSelect="true" />
</ClientSettings>


2. Place the select column/row checkbox
<telerik:RadGrid ...>
<ClientSettings ...>...</ClientSettings>
<MasterTableView...>

<Columns>
       <telerik:GridClientSelectColumn UniqueName="Selectcol" HeaderText="select">
       </telerik:GridClientSelectColumn>
...
</Columns>
</MasterTableView>
</<telerik:RadGrid>

3. Specify the ItemCreated Event
onitemcreated="RadGrid_ItemCreated"

4. Define ItemCreated Event
protected void  RadGrid_ItemCreated(object sender, GridItemEventArgs e)
    {
        GridHeaderItem HeaderItem;
        GridDataItem DateItem;
        CheckBox chkbx=new CheckBox();
        if (e.Item is GridHeaderItem)
        {
            HeaderItem = (GridHeaderItem)e.Item;
            chkbx = (CheckBox)HeaderItem["SelectCol"].Controls[0];
        }
        if (e.Item is GridDataItem)
        {
            DateItem = (GridDataItem)e.Item;
            chkbx = (CheckBox)DateItem["SelectCol"].Controls[0];
        }      
        chkbx.AutoPostBack = true;
        chkbx.CheckedChanged += new EventHandler(chkbx_CheckedChanged);
    }
5. Define chkbx_CheckedChanged

void chkbx_CheckedChanged(object sender, EventArgs e)
{
}

Enjoy...:)

4 comments:

Anonymous said...

I found this useful. I was able to isolate the header checkbox click into a server side event with this. With this, I could update a label with the selected items count when the header checkbox is clicked.

Anonymous said...

awesome, i burned hours today trying to figure this out before stumbling upon your page. 2 minutes later it works. Thanks!

Adeel Nasir said...

Good. Sorry for late reply 😊

Adeel Nasir said...

Good, sorry for late reply