RadGrid for ASP .NET version
RadControls for ASP .NET AJAX version |
4.5.0 and later
2008.1.415 and later
|
.NET version |
2.0 and later
|
Visual Studio version |
2005 and later
|
Programming language |
VB and C#
|
Browser support |
all supported by RadGrid for ASP .NET
all browsers supported by RadControls for ASP .NET AJAX
|
PROJECT DESCRIPTION
This project presents how to select/deselect all rows in a group by means of a checkbox residing in each group header. To accomplish this task the grid group header item is modified - the checkbox is added inside the ItemCreated and ItemDataBound event handlers. The duplicate call to CreateHeaderControls() method is because the controls in the group headers should be recreated when the grid is databound as well as on any other postback. The AutoPostBack property of the checkbox control is set to true and all child items involved are selected server-side.
Alternatively, a checkbox column toggling a server-side item selection might be added. An example of such column may be found
here.
A limitation in this implementation is the fact that group header items text is lost during the process of adding the checkbox.
Following is the code of the method that adds a checkbox control to grid group header items:
private void CreateHeaderControls(GridItemEventArgs e) |
{ |
if (e.Item is GridGroupHeaderItem) |
{ |
GridGroupHeaderItem item = e.Item as GridGroupHeaderItem; |
DataRowView groupDataRow = (DataRowView)e.Item.DataItem; |
CheckBox check = new CheckBox(); |
check.AutoPostBack = true; |
check.ID = "CheckAll"; |
check.Text = "Select all items in group "; |
check.CheckedChanged += new EventHandler(check_CheckedChanged); |
item.DataCell.Controls.Add(check); |
} |
} |
} |
|
Private Sub CreateHeaderControls(ByVal e As GridItemEventArgs) |
If TypeOf e.Item Is GridGroupHeaderItem Then |
Dim item As GridGroupHeaderItem = e.Item |
item.DataCell.Controls.Clear() |
Dim check As New CheckBox() |
check.AutoPostBack = True |
check.ID = "CheckAll" |
check.Text = "Select all items in group " |
AddHandler check.CheckedChanged, AddressOf check_CheckedChanged |
item.DataCell.Controls.Add(check) |
End If |
End Sub |
|