0

Morning all.

I have the followingh scenario where I have a radgrid and inside it, I have a template column containing a check box:

    <telerik:GridTemplateColumn UniqueName="TemplateColumn" HeaderText="Display Information" >
<ItemTemplate>
<asp:Panel ID="Panel1" runat="server">
<asp:CheckBox ID="CheckBox1" runat="server" AutoPostBack="true" OnCheckedChanged="CheckedChanged" />
</asp:Panel>
</ItemTemplate>
</telerik:GridTemplateColumn>

Upon being checked, the following event is fired, which in it's simplistic fashion, changes the style of the data items:

protected void CheckedChanged(object sender, EventArgs e)
        {
            {
                var chkBox = (sender as CheckBox);
                var myPanel = chkBox.Parent as Panel;
                var dataItem = myPanel.NamingContainer as GridDataItem;
                var cell = dataItem["Id"].Text;

                if (chkBox.Checked)
                {
                    dataItem["Id"].Style["color"] = "orange"; 
                    dataItem["Desc"].Style["color"] = "orange";                   
                }
                else
                {
                    dataItem["Id"].Style["color"] = "black"; 
                    dataItem["Desc"].Style["color"] = "black";
                }
            }
        }

This works as expected and does the job.

However, I only really want the user to be able to select one checkbox at a time.

Therefore, how to I go about ensuring that the any previous 'checks' are removed or stopping multiple checking altogether?

Any help or suggestions greatly appreciated.

  • look here: http://stackoverflow.com/questions/775628/jquery-functions-for-operations-on-gridview-with-checkboxes/775676#775676 – Tim Schmelter Mar 11 '11 at 10:29

1 Answers1

0

First why not use a radion button instead and then give all the radio buttons the same NAME tag. That will "group" them together and only one can be selected at once.

Edit: Your other option if must have check boxes is to just clear them all out in the event in either code behind or in a JavaScript.

Cheers, Stefan

StefanE
  • 7,578
  • 10
  • 48
  • 75
  • Hello Stefan - I tried the radio button option but this also allowed mutliple selection. I'll try grouping them and see how I go : ) – Unknown Soldier Mar 11 '11 at 10:32
  • I think he would run into the bug i mentioned [here](http://stackoverflow.com/questions/5147371/radio-option-groupname-problem-in-dynamic-loading-user-control-asp-net/5147772#5147772) if he would use RadioButtons in a GridView (unique-names issue). – Tim Schmelter Mar 11 '11 at 10:32
  • I guess this might be working if you are using .NET 4.0 and static naming of dynamically created controls.. I will try do a test with it – StefanE Mar 11 '11 at 10:35
  • Yuppers, using 4.0. Thanks for the suggestions. – Unknown Soldier Mar 11 '11 at 10:37