首页 > 代码库 > GridView全局仅能选择一个复选框

GridView全局仅能选择一个复选框

//全局仅能选择一个复选框

function CheckLimit(check) {
            var inputs = document.getElementsByTagName("input");
            for (var i = 0; i < inputs.length; i++) {
                if (inputs[i].type == "checkbox") {
                    inputs[i].checked = false;
                }
            }
            check.checked = true;
        }

控件

 <asp:GridView ID="gvwInfo" runat="server" Width="654px"
                                                                    EmptyDataText="无信息!">
                                                                    <EmptyDataRowStyle ForeColor="Red" HorizontalAlign="Center" />
                                                                    <Columns>
                                                                        <asp:TemplateField>
                                                                            <ItemTemplate>
                                                                                <asp:CheckBox ID="SelectData" runat="server" onclick="ColumnCheckLimit(this)"/>//调用JS方法
                                                                            </ItemTemplate>
                                                                            <ItemStyle HorizontalAlign="Center" />
                                                                            <HeaderStyle Width="8%" HorizontalAlign="Center" />
                                                                        </asp:TemplateField>
                                                                        <asp:BoundField HeaderText="名称" DataField="NAME">
                                                                            <ItemStyle Width="40%" HorizontalAlign="Center" />
                                                                            <HeaderStyle Width="40%" HorizontalAlign="Center" />
                                                                        </asp:BoundField>
                                                                </Columns>
                                                                </asp:GridView>