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

Select All Rows Event

5 Answers 576 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Paul
Top achievements
Rank 1
Paul asked on 29 Oct 2010, 08:49 AM
Hi,

I have a RadGrid, containing a GridClientSelectColumn.
I am using server side event processing, and I get the SelectedIndexChanged event whenver a row is clicked or a checkbox is changed.
However, if the checkbox in the header is clicked, to select / deselect all grid items then I do not receive an event, even though the selected items have obviously changed.
I am using the lastest set of controls (Sep - Q2 SP2)

Should I be looking for a different event, or is there another way to get this working?

Thanks.

Paul

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 29 Oct 2010, 11:34 AM
Hello Paul,

You can achieve this by accessing the CheckBox in header item and attach a 'CheckedChange' event to the Checkbox. Sample code is given below.

ASPX:
<telerik:GridClientSelectColumn UniqueName="GridClientSelectColumn">
</telerik:GridClientSelectColumn>

By using following condition inside the OnSelectedIndexChanged event of RadGrid, you can differentiate whether the CheckBox in grid item or the CheckBox in header item is clicked.

C#:
protected void RadGrid1_SelectedIndexChanged(object sender, EventArgs e)
{
    GridHeaderItem headerItem = (GridHeaderItem)RadGrid1.MasterTableView.GetItems(GridItemType.Header)[0];
    CheckBox headerChkBox = (CheckBox)headerItem["GridClientSelectColumn"].Controls[0];
    if (headerChkBox.Checked)
    {
        // header CheckBox is clicked
    }
    else
    {
       // check box inside Grid row is clicked
    }
     
}
protected void RadGrid1_ItemCreated(object sender, GridItemEventArgs e)
{
    if (e.Item is GridHeaderItem)
    {
        GridHeaderItem headerItem = (GridHeaderItem)e.Item;
        CheckBox headerChkBox = (CheckBox)headerItem["GridClientSelectColumn"].Controls[0];
        headerChkBox.AutoPostBack = true;
        headerChkBox.CheckedChanged += new EventHandler(headerChkBox_CheckedChanged);
    }
}
 
void headerChkBox_CheckedChanged(object sender, EventArgs e)
{
    // Here is your code when header clicked
}

Thanks,
Princy.
0
Paul
Top achievements
Rank 1
answered on 29 Oct 2010, 12:06 PM
Thanks Princy,

That worked a treat!

Paul
0
Thomas Derenthal
Top achievements
Rank 1
answered on 04 Nov 2014, 01:55 PM
Thank you. This is just what I need,
0
Thomas Derenthal
Top achievements
Rank 1
answered on 04 Nov 2014, 01:56 PM
Thank you. This is just what I needed.
0
Thomas Derenthal
Top achievements
Rank 1
answered on 04 Nov 2014, 01:57 PM
Multiple replies because the post kept causing a 500 error.
Tags
Grid
Asked by
Paul
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Paul
Top achievements
Rank 1
Thomas Derenthal
Top achievements
Rank 1
Share this question
or