验证asp.net中的复选框 [英] validation of checkboxlist in asp.net

查看:80
本文介绍了验证asp.net中的复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在用数据库填充CheckBoxList.现在,我要验证CheckBoxList的填充项.


请帮忙.

谢谢

Hi All,

I am populating a CheckBoxList with database. Now I want to validate the populated item of CheckBoxList.


Please help.

Thanks

推荐答案

如果您正在寻找Checkbox列表所需的验证,请查看此代码,否则发布您的要求.

If you are looking required validation for Checkbox list then look into this code otherwise post your requirement.

//Bound list from Database
<asp:checkboxlist id="chlZones" runat="server" repeatcolumns="5" repeatdirection="Horizontal" />
//Create Custom validator that will work as required validator. Profile function
<asp:customvalidator id="cvalZones" runat="server" clientvalidationfunction="ValidateZones" errormessage="!!!" display="Dynamic" />
 
//Implement Client method
<script>
function ValidateZones(source, args) {
		var chlZones = document.getElementById('''');
		var chkLista = chlZones.getElementsByTagName("input");
		for (var i = 0; i < chkLista.length; i++) {
			if (chkLista[i].checked) {
				args.IsValid = true;
				return;
			}
		}
		args.IsValid = false;
	}
</script>


这篇关于验证asp.net中的复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆