[英]How to add Required Field Validator to checked ListBox?
I'm using a checked list-box inside a div tag and I want to validate the checked list-box. 我在div标签中使用了选中的列表框,我想验证选中的列表框。 How can I achieve this?
我该如何实现?
You can use javascript to validate the checkboxlist. 您可以使用javascript来验证复选框列表。 please find the below code to get an idea:
请找到以下代码来了解一下:
<script type = "text/javascript">
var minOccurance= 1
function Validate()
{
var yourCheckboxList= document.getElementById("<%=CheckBoxList1.ClientID%>");
var checkbox = yourCheckboxList.getElementsByTagName("input");
var counter=0;
for (var i=0;i<checkbox.length;i++)
{
if (checkbox[i].checked)
counter++;
}
if(minOccurance>counter)
{
alert("Please select atleast " + minOccurance + " item(s)");
return false;
}
return true;
}
</script>
Hope this will you to solve the issue. 希望这能解决您的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.