如何只检查gridview中的一个复选框

时间:2012-12-17 06:59:40

标签: c# asp.net

我正在使用gridview,我的问题是如果用户选择第二个复选框,用户只能在网格中选择一个复选框,我们将取消选中。我尝试javascript,但这不适合我,你能帮我,我怎么能这样做。以下是我的gridview

    <data:EntityGridView ID="gvService" Width="100%"  DataKeyNames="PriceSystemID" runat="server"
                                            OnRowEditing="GridView1_RowEditing" OnRowCommand="gvServices_ItemCommand" AutoGenerateColumns="False"
                                            OnRowDeleting="gvService_RowDeleting" ShowFooter="true" OnRowCancelingEdit="gvService_RowCancelingEdit" 
                                            >
                                            <Columns>
                                                <asp:TemplateField HeaderText="Service">
                                                    <ItemTemplate>
                                                        <data:EntityDropDownList runat="server" ID="dataServiceTypeId1"  DataSourceID="ServiceTypeIdServiceTypesDataSource"
                                                            DataTextField="Description" DataValueField="ServiceTypeId" SelectedValue='<%# Bind("ServiceTypeID") %>' Width="200px"
                                                            AppendNullItem="true" Required="true" NullItemText="< Please Choose ...>" ErrorText="Required" />
                                                        <data:ServiceTypesDataSource ID="ServiceTypeIdServiceTypesDataSource" runat="server"
                                                            SelectMethod="GetAll" />
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <data:EntityDropDownList runat="server" ID="dataServiceTypeId2" DataSourceID="ServiceTypeIdServiceTypesDataSource"
                                                             DataTextField="Description" DataValueField="ServiceTypeId" Width="200px" AutoPostBack="true"
                                                            SelectedValue='<%# Bind("ServiceTypeID") %>' AppendNullItem="true" Required="true"
                                                            NullItemText="< Please Choose ...>" ErrorText="Required" />
                                                        <data:ServiceTypesDataSource ID="ServiceTypeIdServiceTypesDataSource" runat="server"
                                                            SelectMethod="GetAll" />
                                                    </EditItemTemplate>
                                                    <FooterTemplate>
                                                      <data:EntityDropDownList runat="server" ID="dataServiceTypeId3" DataSourceID="ServiceTypeIdServiceTypesDataSource"
                                                            AutoPostBack="true" DataTextField="Description" DataValueField="ServiceTypeId" Width="200px"
                                                            SelectedValue='<%# Bind("ServiceTypeID") %>' AppendNullItem="true" Required="true"
                                                            NullItemText="< Please Choose ...>" ErrorText="Required" />
                                                        <data:ServiceTypesDataSource ID="ServiceTypeIdServiceTypesDataSource" runat="server"
                                                            SelectMethod="GetAll" />
                                                    </FooterTemplate>
                                                </asp:TemplateField>
                                                <asp:TemplateField HeaderText="Default">
                                                    <ItemTemplate>
                                                        <asp:CheckBox ID="chkDefault" Checked='<%# Bind("IsDefault") %>'   
                                                            runat="server" />
                                                    </ItemTemplate>
                                                    <EditItemTemplate>
                                                        <asp:CheckBox ID="chkDefault" Checked='<%# Bind("IsDefault") %>' runat="server"   />
                                                    </EditItemTemplate>
                                                    <FooterTemplate>
                                                      <asp:CheckBox ID="chkDefault" Checked='<%# Bind("IsDefault") %>' runat="server"   />

                                                    </FooterTemplate>
                                                </asp:TemplateField>

                                                                                                                                                                                  'CausesValidation =“false”&gt;                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  <EmptyDataTemplate>
 </EmptyDataTemplate>

    </data:EntityGridView>

1 个答案:

答案 0 :(得分:1)

一个基本问题(可能是您的答案):如果用户只能选择一个,为什么要使用复选框。使用单选按钮代替正确的分组,浏览器将负责单一选择。希望我足够清楚。当用户有多个选择可供选择时,使用复选框,否则,使用单选按钮进行单选。