Single selection within each group of RadGrid

Thread is closed for posting
2 posts, 0 answers
  1. Telerik Admin
    Telerik Admin avatar
    1679 posts
    Member since:
    Oct 2004

    Posted 07 May 2007 Link to this post


    RadGrid for ASP .NET version

    RadControls for ASP .NET AJAX version
    4.6.0 and later

    2008.1.415 and later
    .NET version

    2.0 and later

    Visual Studio version

    2005 and later

    Programming language


    Browser support

    all supported by RadGrid for ASP .NET

    all browsers supported by RadControls for ASP .NET AJAX

    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:

        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;  

    Public Sub CheckedChanged(ByVal sender As ObjectByVal 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 
    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.
  2. Chinmay
    Chinmay avatar
    4 posts
    Member since:
    Sep 2008

    Posted 16 Sep 2008 Link to this post

Back to Top