在.net中用CheckBoxList實現(xiàn)單選
更新時間:2014年02月11日 10:33:12 作者:
用CheckBoxList實現(xiàn)單選的原因是我覺得CheckBoxList控件頁面展示效果要好看一些,需要的朋友可以參考下
在.net中提供了Radiobuttonlist來實現(xiàn)單選的,但是我一直喜歡用CheckBoxList 原因我覺得CheckBoxList 控件頁面展示效果要好看一些,呵呵
這里是先CheckBoxList 實現(xiàn)單選采用了控件的點擊事件 調(diào)用js來控制單選的
例如頁面如下:
<asp:CheckBoxList ID="CheckBoxList1" BorderWidth="1" runat="server" RepeatLayout="Flow">
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item1">Item1</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item2">Item2</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item3">Item3</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item4">Item4</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item5">Item5</asp:ListItem>
</asp:CheckBoxList>
這里是調(diào)用的js
原理就是:
1、獲得頁面控件集合,循環(huán)查找check
2、設置check 為false ,再將傳入的控件設置選中
function CheckBoxList_Click(sender)
{
var container = sender.parentNode;
if(container.tagName.toUpperCase() == "TD") { // 服務器控件設置呈現(xiàn)為 table 布局(默認設置),否則使用流布局
container = container.parentNode.parentNode; // 層次: <table><tr><td><input />
}
var chkList = container.getElementsByTagName("input");
var senderState = sender.checked;
for(var i=0; i<chkList.length;i++) {
chkList[i].checked = false;
}
sender.checked = senderState;
}
這里是先CheckBoxList 實現(xiàn)單選采用了控件的點擊事件 調(diào)用js來控制單選的
例如頁面如下:
復制代碼 代碼如下:
<asp:CheckBoxList ID="CheckBoxList1" BorderWidth="1" runat="server" RepeatLayout="Flow">
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item1">Item1</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item2">Item2</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item3">Item3</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item4">Item4</asp:ListItem>
<asp:ListItem onclick="CheckBoxList_Click(this)" Value="Item5">Item5</asp:ListItem>
</asp:CheckBoxList>
這里是調(diào)用的js
原理就是:
1、獲得頁面控件集合,循環(huán)查找check
2、設置check 為false ,再將傳入的控件設置選中
復制代碼 代碼如下:
function CheckBoxList_Click(sender)
{
var container = sender.parentNode;
if(container.tagName.toUpperCase() == "TD") { // 服務器控件設置呈現(xiàn)為 table 布局(默認設置),否則使用流布局
container = container.parentNode.parentNode; // 層次: <table><tr><td><input />
}
var chkList = container.getElementsByTagName("input");
var senderState = sender.checked;
for(var i=0; i<chkList.length;i++) {
chkList[i].checked = false;
}
sender.checked = senderState;
}
您可能感興趣的文章:
- MVC實現(xiàn)下拉框聯(lián)動效果(單選)
- 詳解ASP.NET MVC之下拉框綁定四種方式
- ASP.NET MVC下拉框聯(lián)動實例解析
- asp.net mvc下拉框Html.DropDownList 和DropDownListFor的常用方法
- 基于MVC3方式實現(xiàn)下拉列表聯(lián)動(JQuery)
- asp.net 自制的單選、多選列表實現(xiàn)代碼
- asp.net中js+jquery添加下拉框值和后臺獲取示例
- ASP.NET中DropDownList下拉框列表控件綁定數(shù)據(jù)的4種方法
- asp.net 實現(xiàn)下拉框只讀功能
- MVC5下拉框綁定的方法(單選)
相關(guān)文章
在ASP.NET?Core微服務架構(gòu)下使用RabbitMQ實現(xiàn)CQRS模式的方法
ASP.NET Core微服務架構(gòu)中,使用RabbitMQ作為消息隊列服務,通過實現(xiàn)CQRS模式,將寫操作和讀操作分離,以提高系統(tǒng)的性能和可伸縮性,本文小編將為大家介紹如何在ASP.NET Core微服務架構(gòu)下使用RabbitMQ來實現(xiàn)CQRS模式,感興趣的朋友一起看看吧2024-01-01ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺管理系統(tǒng)之前端頁面框架構(gòu)建源碼分享
這篇文章主要為大家分享了ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺管理系統(tǒng)之easyui前端頁面框架構(gòu)建源碼,感興趣的小伙伴們可以參考一下2016-07-07如何使用ASP.NET創(chuàng)建網(wǎng)站并設計web頁面
這篇文章主要介紹了如何使用ASP.NET創(chuàng)建網(wǎng)站,幫助大家更好的理解和學習使用ASP.NET技術(shù),感興趣的朋友可以了解下2021-04-04.NET?Framework?的項目如何使用?FTP?下載文件
本文專門針對面向?.NET?Framework?的項目,?對于面向?.NET?6?及更高版本的項目,不再支持?FTP,此示例演示如何從?FTP?服務器下載文件,感興趣的朋友跟隨小編一起看看吧2024-01-01