Telerik
Skip Navigation LinksHome / Community / Code Library / ASP.NET and ASP.NET AJAX > Grid > Single selection within each group of RadGrid

Answered Single selection within each group of RadGrid

Feed from this thread
  • Telerik Admin MVP avatar

    Posted on May 7, 2007 (permalink)

    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 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 
        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.

  • Chinmay avatar

    Posted on Sep 16, 2008 (permalink)

     

Back to Top

Skip Navigation LinksHome / Community / Code Library / ASP.NET and ASP.NET AJAX > Grid > Single selection within each group of RadGrid

Powered by Sitefinity ASP.NET CMS

Contact Us | Site Feedback | Terms of Use | Privacy Policy
Copyright © 2002-2010 Telerik. All rights reserved.