ASP.NET - Code Samples - Disable CheckboxList Items
2007-01-16 09:54
337 查看
//Add This Code To the HTML directly
// checkboxlistID = id of the checkboxlist
// chkarray = array of indexes to set enable or disable
// disable = true to disable
<script language=javascript>
function disableListItems(checkBoxListId, chkArray, disable)
{
// Get the checkboxlist object.
objCtrl = document.getElementById(checkBoxListId);
// Does the checkboxlist not exist?
if(objCtrl == null)
{ return;
}
var i = 0;
// iterate through listitems that need to be enabled or disabled
for(i = 0; i<chkArray.length; i++)
{
objItem = document.getElementById(checkBoxListId + '_' + chkArray[i]);
if(objItem == null)
{
continue;
}
// Disable/Enable the checkbox.
objItem.disabled = disable;
// Should the checkbox be disabled?
objItem.checked = false;
}
}
</script>
'Add Code to the page load event (this demonstrates disabling the 2nd and 3rd items)
'Disable on intial Page Load
If Not Me.IsStartupScriptRegistered("doit") Then
Me.RegisterStartupScript("doit", "<script language=""javascript"">disableListItems('checkBoxList1',new Array(1,2),true);</script>")
End if
'Disable on checkboxlist click
CheckBoxList1.Attributes.Add("onclick", _
"disableListItems('checkBoxList1',new Array(1,2),true)")
// checkboxlistID = id of the checkboxlist
// chkarray = array of indexes to set enable or disable
// disable = true to disable
<script language=javascript>
function disableListItems(checkBoxListId, chkArray, disable)
{
// Get the checkboxlist object.
objCtrl = document.getElementById(checkBoxListId);
// Does the checkboxlist not exist?
if(objCtrl == null)
{ return;
}
var i = 0;
// iterate through listitems that need to be enabled or disabled
for(i = 0; i<chkArray.length; i++)
{
objItem = document.getElementById(checkBoxListId + '_' + chkArray[i]);
if(objItem == null)
{
continue;
}
// Disable/Enable the checkbox.
objItem.disabled = disable;
// Should the checkbox be disabled?
objItem.checked = false;
}
}
</script>
'Add Code to the page load event (this demonstrates disabling the 2nd and 3rd items)
'Disable on intial Page Load
If Not Me.IsStartupScriptRegistered("doit") Then
Me.RegisterStartupScript("doit", "<script language=""javascript"">disableListItems('checkBoxList1',new Array(1,2),true);</script>")
End if
'Disable on checkboxlist click
CheckBoxList1.Attributes.Add("onclick", _
"disableListItems('checkBoxList1',new Array(1,2),true)")
相关文章推荐
- 黑马程序员 ASP.NET中 CheckboxList.Items.Count=0的解决办法
- Check/Uncheck all Items in an ASP.NET CheckBox List using jQuery
- ASP.NET - CheckBox 和 CheckBoxList Web 服务器控件概述(上)
- 用JavaScript获取Asp.net服务器端控件CheckBoxList的选中值数组(转)
- ASP.NET jQuery 食谱5 (显示CheckBoxList成员选中的内容)
- asp.net的checkboxlist绑定数据
- ASP.NET 2.0中的友好CSS控件适配器的应用 - 用ul、li呈现CheckBoxList和RadioButtonList
- Csharp:asp.net CheckBoxList databind
- Asp.net(C#/2.0) 部分全选 CheckBoxList
- 【翻译】ASP.NET MVC:转化业务对象到Select List Items上
- 在ASP.NET MVC中使用“RadioButtonList”和“CheckBoxList”
- ASP.NET页面的CheckBoxList组件(资料)
- 学习记录 asp.net c#连接sql server 2012 调用存储过程 用返回的记录填充CheckBoxList 都是常用的,特此记录
- asp.net中repeater嵌套CheckBoxList,RadioButtonList来完成投票
- ASP.Net页面中,DropDownList、CheckBoxList控件和页面中动态控件的冲突
- 如何在asp.net中取出CheckBoxList中的元素 并存进数据库中
- ASP.NET中用js取CheckBoxList中值的方法实例
- Validation CheckBoxList in asp.net form
- ASP.NET jQuery 食谱15 (通过控件CustomValidator验证CheckBoxList)
- ASP.NET MVC 3 CheckBoxList 的使用