简体   繁体   English

如何在gridview中只允许一个复选框?

[英]How to allow only one checked box in the gridview?

If i have a grid view contains checkbox chk_short_day as template field : 如果我有一个网格视图,其中包含checkbox chk_short_day作为模板字段:

<asp:GridView ID="grv_week_day" runat="server" AutoGenerateColumns="False" 
     CssClass="datatable" OnRowDataBound="grv_week_day_RowDataBound" >
<Columns>
    <asp:TemplateField HeaderStyle-Height="40px" HeaderStyle-Width="200px">
        <HeaderTemplate>
            <h2>week days
            </h2>
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="lbl_weekday" runat="server" CssClass="title" Text='<%# Bind("WeekDay") %>'></asp:Label>
        </ItemTemplate>
        <HeaderStyle Height="40px" Width="100px"></HeaderStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderStyle-Height="40px">
        <HeaderTemplate>
            <h2>Attendance Type</h2>
        </HeaderTemplate>
        <ItemTemplate>
            <asp:DropDownList ID="drp_att" runat="server" AutoPostBack="True" Width="200px" Enabled="false"
                CausesValidation="false" OnSelectedIndexChanged="OnSelectedIndexChanged_drp">
            </asp:DropDownList>
        </ItemTemplate>
        <HeaderStyle Height="40px"></HeaderStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderStyle-Height="40px">
        <HeaderTemplate>
            <h2>From
            </h2>
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="lbl_From" runat="server"></asp:Label>
        </ItemTemplate>
        <HeaderStyle Height="40px"></HeaderStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderStyle-Height="40px">
        <HeaderTemplate>
            <h2>To
            </h2>
        </HeaderTemplate>
        <ItemTemplate>
            <asp:Label ID="lbl_To" runat="server"></asp:Label>
        </ItemTemplate>
        <HeaderStyle Height="40px"></HeaderStyle>
    </asp:TemplateField>
    <asp:TemplateField HeaderText="Short Day">
        <ItemTemplate>
            <asp:CheckBox ID="chk_short_day" runat="server" AutoPostBack ="true" OnCheckedChanged="chk_short_day_CheckedChanged"   />
        </ItemTemplate>
    </asp:TemplateField>
</Columns>


How to allow only one checked in the gridview , If the user check one of the check boxes ,i want to uncheck the rest automatically .? 如何只允许在网格视图中选中一个,如果用户选中其中一个复选框,我想自动取消选中其余复选框。

How about using a radio button instead? 如何使用单选按钮呢? Only one radio button within the same Group are allowed to be selected. 只能选择同一组中的一个单选按钮。

<asp:TemplateField HeaderText="Short Day">
   <ItemTemplate>
       <asp:RadioButton id="rbt_short_day" GroupName="shortDay"/>
   </ItemTemplate>
</asp:TemplateField>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM