views:

63

answers:

2

I'm trying to set up two check box's in a DataGrid so that only one can be checked at any one time.

At the moment, the following renders the existing state of the choice on screen:

<asp:TemplateColumn HeaderText="Choice One">
    <ItemTemplate>
        <asp:CheckBox ID="CheckBoxChoiceOne" 
                      CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ChoiceOne") %>'
                     runat="server">
        </asp:CheckBox>
    </ItemTemplate>
</asp:TemplateColumn>
    <asp:TemplateColumn HeaderText="Choice Two">
    <ItemTemplate>
          <asp:CheckBox ID="CheckBoxChoiceTwo" 
                        CommandArgument='<%# DataBinder.Eval(Container.DataItem, "ChoiceTwo") %>'
                        runat="server">
          </asp:CheckBox>
    </ItemTemplate>
</asp:TemplateColumn>

How do I go about ensuring that if the user chooses ChoiceOne that any selection of ChoiceTwo will be unselected and vice versa? Is there any way to state in the DataGrid control that these two checkboxes are grouped together?

+5  A: 

This is a situation for Radio Buttons instead of checkboxes. You are violating user expectations if you have checkboxes behave in that manner. From a UI perspective that isn't a great idea.

Matt
+1 Yup, Radio Buttons, that's the answer
LeonixSolutions
A: 

You should use radio buttons for this purpose.

mpenrow