想让CheckBoxList 成为单选,要在选中事件时候绑定一个js方法
1 <asp:CheckBoxList ID="cblComments" runat="server" OnSelectedIndexChanged="cblComments_SelectedIndexChanged" AutoPostBack="true"> 2 <asp:ListItem Text="Agree" Value="Agree" onclick="CheckCBLSimpleSelect(this)"></asp:ListItem> 3 <asp:ListItem Text="Disagree" Value="Disagree" onclick="CheckCBLSimpleSelect(this)"></asp:ListItem> 4 </asp:CheckBoxList>
js方法为:
1 /*let CheckBoxList be Simple Checked*/ 2 function CheckCBLSimpleSelect(sender) { 3 var container = sender.parentNode; 4 if (container.tagName.toUpperCase() == "TD") { // 服务器控件设置呈现为 table 布局(默认设置),否则使用流布局 5 container = container.parentNode.parentNode; // 层次: <table><tr><td><input /> 6 } 7 var chkList = container.getElementsByTagName("input"); 8 var senderState = sender.checked; 9 for (var i = 0; i < chkList.length; i++) { 10 chkList[i].checked = false; 11 } 12 sender.checked = senderState; 13 //checkTotal()//count checked checkbox num 14 }
标签:container,sender,C#,CheckBoxList,单选,var,checked From: https://www.cnblogs.com/zhangbupangpang/p/16937722.html