如何在 gridview 中只允许一个复选框?
How to allow only one checked box in the gridview?
如果我有一个网格视图包含 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>
如何在gridview中只允许选中一个,如果用户选中其中一个复选框,我想自动取消选中其余的复选框。?
改用单选按钮怎么样?同一组内的单选按钮只能选择一个。
<asp:TemplateField HeaderText="Short Day">
<ItemTemplate>
<asp:RadioButton id="rbt_short_day" GroupName="shortDay"/>
</ItemTemplate>
</asp:TemplateField>
如果我有一个网格视图包含 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>
如何在gridview中只允许选中一个,如果用户选中其中一个复选框,我想自动取消选中其余的复选框。?
改用单选按钮怎么样?同一组内的单选按钮只能选择一个。
<asp:TemplateField HeaderText="Short Day">
<ItemTemplate>
<asp:RadioButton id="rbt_short_day" GroupName="shortDay"/>
</ItemTemplate>
</asp:TemplateField>