Limit one selection per group

2 posts, 0 answers
  1. Amanda Shafer
    Amanda Shafer avatar
    2 posts
    Member since:
    Oct 2012

    Posted 17 Jan 2012 Link to this post

    Is there a way to limit client-side row selection to one row per grouping in a radgrid without causing a postback every time?

    I used an old example (see below), but each click of a checkbox causes a postback which is disruptive to the process. I wasn't sure if there was some built in functionality or an easy way to check at the end if too many were selected.

    Thank you..

    <radG:GridTemplateColumn UniqueName="CheckBoxColumn">
       <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckedChanged" />

    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;
  2. Tsvetina
    Tsvetina avatar
    2102 posts

    Posted 19 Jan 2012 Link to this post

    Hello Amanda,

    There is no indication of grouping in RadGrid's client object, so your requirement cannot be achieved using the control's API. You could try achieving this by some custom logic traversing the DOM element of the grid and keeping track of the CSS classes applied to elements. However, this would require a lot of scenario-specific custom code and we do not have an example of such solution.

    An easier approach would be to go with the server-side solution and use AJAX to avoid full page reload on each selection.  

    Kind regards,
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Back to Top