This is a migrated thread and some comments may be shown as answers.

Limit one selection per group

1 Answer 28 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amanda Shafer
Top achievements
Rank 2
Amanda Shafer asked on 17 Jan 2012, 04:08 PM
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">
 <ItemTemplate>
   <asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckedChanged" />
 </ItemTemplate>
</radG:GridTemplateColumn>

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;
            }
        }
    }

1 Answer, 1 is accepted

Sort by
0
Tsvetina
Telerik team
answered on 19 Jan 2012, 10:59 AM
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,
Tsvetina
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
Tags
Grid
Asked by
Amanda Shafer
Top achievements
Rank 2
Answers by
Tsvetina
Telerik team
Share this question
or