日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > asp.net >内容正文

asp.net

ASP.NET DEMO 12 : CheckBoxList 实现单选

發布時間:2025/7/14 asp.net 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 ASP.NET DEMO 12 : CheckBoxList 实现单选 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一看標題估計大家都開始懷疑了:單選?為什么不直接使用 RadioButtonList ?
是的。你是對的。然而,實際應用中需求千變萬化,誰讓我們的客戶夠 BT 呢?

主要代碼

只有一個通用的 CheckBoxList_Click 函數,
需要注意的是 CheckBoxList 可以呈現為 table 布局,也可以呈現為流布局(使用 span 做外部容器)

我的習慣是,腳本代碼中,盡量不直接引用 html id,因為對于服務器控件對應的是 ClientID,而ClientID與控件層次關聯的,不利于代碼移植復用,因此盡可能選擇直接傳遞對象,通過 DOM 獲取相關的父控件和子控件。

function?CheckBoxList_Click(sender)?
????
{
????????
var?container?=?sender.parentNode;????????
????????
if(container.tagName.toUpperCase()?==?"TD")?{?//?服務器控件設置呈現為?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;??????????
????}

<h3>單選效果的?CheckBoxList</h3>
????
<div?style="float:left">
????
<h4>靜態項</h4>
????????
<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>
????
</div>
????
<div?style="float:left;padding-left:100px">
????
<h4>綁定項</h4>
????????
<asp:CheckBoxList?ID="CheckBoxList2"?BorderWidth="1"?runat="server"?DataTextField="Value"?DataValueField="Key"?OnDataBound="CheckBoxList2_DataBound">????????
????????
</asp:CheckBoxList>
????
</div>
兼容性
IE 6 SP6, ?FF 2.0, ?Opera 9.2 測試通過

頁面效果



下載

轉載于:https://www.cnblogs.com/Jinglecat/archive/2007/07/18/823201.html

總結

以上是生活随笔為你收集整理的ASP.NET DEMO 12 : CheckBoxList 实现单选的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。