两个CheckBoxList控件关联选择的问题
我现在有两个CheckBoxList,一个名为“ChkArea”;一个名为“ChkCity”;ChkArea从表Dic_Area中读取数据,ChkCity从表Dic_Province中读取数据,这两个表里都有一个字段DicArea用来关联,我现在想要达到的目的是,当我选择或取消选择ChkArea中的某一项时,ChkCity中DicArea等于ChkArea所选择的那一项DicArea值得所有项都要选中或被取消,就是两个控件之间的状态通过DicArea值来关联。
不知道我叙述清楚了马,希望大家给个解决办法,应该需要用JS,但是怎么样触发这个方法?DicArea的值怎么传进去,传进去了后,怎么选中等于DicArea的那些ITEM项?
注:我用的是.NET2005
------解决方案-------------------- <script language= "JavaScript ">
<!--
function chkClk(obj){
var chks=document.getElementsByName(obj.name);
//alert(chks.length);
if(obj.flag){
for(var i=1;i <chks.length;i++)
chks[i].checked=obj.checked;
}
else{
for(var i=1;i <chks.length;i++)
if(chks[i].checked==false){
chks[0].checked=false;
break;
}
else{
if(i==chks.length-1) chks[0].checked=true;
}
}
}
//-->
</script>
<input type= "checkbox " onclick= "chkClk(this) " name= "type1 " flag= "main "> typetext
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type1 "> typetext </li>
<br> <br>
<input type= "checkbox " onclick= "chkClk(this) " name= "type2 " flag= "main "> typetext
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
<li> <input type= "checkbox " onclick= "chkClk(this) " name= "type2 "> typetext </li>
------解决方案--------------------我才发现checkboxlist控件生成的html是这样的。。。
<table id= "CheckBoxList1 " border= "0 ">
<tr>
<td> <input id= "CheckBoxList1_0 " type= "checkbox " name= "CheckBoxList1$0 " /> <label for= "CheckBoxList1_0 "> area1 </label> </td>
</tr> <tr>
<td> <input id= "CheckBoxList1_1 " type= "checkbox " name= "CheckBoxList1$1 " /> <label for= "CheckBoxList1_1 "> area2 </label> </td>
</tr> <tr>
<td> <input id= "CheckBoxList1_2 " type= "checkbox " name= "CheckBoxList1$2 " /> <labe