|
Requirements
|
| RadGrid version |
4.6.0
|
| Web.UI version |
2007.3.1425 |
| .NET version |
2.x
|
| Visual Studio version |
2005
|
| programming language |
C#
|
| browser support |
all browsers supported by RadGrid
|
| To convert code |
Telerik online converter |
PROJECT DESCRIPTION
The demo project represents how to restrict only one checkbox to be checked inside each group in RadGrid. The checkboxes reside in item template of template grid column and the logic which regulates their checked state is executed with asynchronous request server-side (inside the
OnCheckedChanged handler of the checkbox).
The idea is to designate the records in the active group and uncheck all of them but the last item clicked by the user:
C#
| public void CheckedChanged(object sender, EventArgs e) |
| { |
| GridDataItem checkedItem = (GridDataItem)(sender as CheckBox).NamingContainer; |
| string checkedItemIndex = checkedItem.GroupIndex.Substring(checkedItem.GroupIndex.LastIndexOf('_'), 2); |
| |
| foreach (GridDataItem item in checkedItem.OwnerTableView.Items) |
| { |
| string currItemIndex = item.GroupIndex.Substring(item.GroupIndex.LastIndexOf('_'), 2); |
| |
| if (checkedItem.GroupIndex.StartsWith(item.GroupIndex.Substring(0,1)) && currItemIndex != checkedItemIndex) |
| { |
| (item.FindControl("CheckBox1") as CheckBox).Checked = false; |
| } |
| } |
| } |
VB.NET
| Public Sub CheckedChanged(ByVal sender As Object, ByVal e As EventArgs) |
| Dim checkedItem As GridDataItem = CType(CType(sender, CheckBox).NamingContainer, GridDataItem) |
| Dim checkedItemIndex As String = checkedItem.GroupIndex.Substring(checkedItem.GroupIndex.LastIndexOf("_"C), 2) |
| |
| For Each item As GridDataItem In checkedItem.OwnerTableView.Items |
| Dim currItemIndex As String = item.GroupIndex.Substring(item.GroupIndex.LastIndexOf("_"C), 2) |
| |
| If checkedItem.GroupIndex.StartsWith(item.GroupIndex.Substring(0, 1)) AndAlso currItemIndex <> checkedItemIndex Then |
| CType(item.FindControl("CheckBox1"), CheckBox).Checked = False |
| End If |
| Next |
| End Sub |
You can extend the logic to select the records along with changing their checked state. To persist the checkbox state on other actions which trigger rebind, review
this documentation article.