ASP.NET服務(wù)器端控件RadioButtonList,DropDownList,CheckBoxList的取值、賦值用法
這三個(gè)控件都有一個(gè)Items集合,可以用 RepeatLayout 和 RepeatDirection 屬性來(lái)控制列表的呈現(xiàn)形式。如果 RepeatLayout 的值為 Table,那么將在表中呈現(xiàn)列表。如果設(shè)置成 Flow,那么將在沒(méi)有任何表結(jié)構(gòu)的情況下呈現(xiàn)列表。默認(rèn)情況下,RepeatDirection 的值為 Vertical。將此屬性設(shè)置成 Horizontal 將會(huì)使列表水平呈現(xiàn)。
RadioButtonList:控件提供已選中一個(gè)選項(xiàng)的單項(xiàng)選擇列表(數(shù)據(jù)源單選)。與其他列表控件相似,RadioButtonList 有一個(gè) Items 集合,其成員與列表中的每個(gè)項(xiàng)目相對(duì)應(yīng)。
DropDownList:下拉列表選擇,對(duì)于有些形式的輸入,用戶(hù)必須從適用選項(xiàng)列表中選擇一個(gè)選項(xiàng)(下拉唯一選擇)。
CheckBoxList:多選列表,將數(shù)據(jù)源以橫向或縱向方式呈現(xiàn)給用戶(hù),用戶(hù)可以進(jìn)行多個(gè)item的選擇。
由于這三個(gè)控件是服務(wù)器端控件,需要在客戶(hù)端進(jìn)行解析,下面有三個(gè)控件的服務(wù)器端、客戶(hù)端例子
服務(wù)器端
<asp:RadioButtonList ID="RadioButtonList1" RepeatDirection="Horizontal" RepeatLayout="Flow"
runat="server">
<asp:ListItem Value="0">單選一</asp:ListItem>
<asp:ListItem Value="1">單選二</asp:ListItem>
<asp:ListItem Value="2">單選三</asp:ListItem>
</asp:RadioButtonList>
<br />
<asp:CheckBoxList ID="CheckBoxList1" RepeatDirection="Horizontal" RepeatLayout="Flow"
runat="server">
<asp:ListItem Value="0">多選一</asp:ListItem>
<asp:ListItem Value="1">多選二</asp:ListItem>
<asp:ListItem Value="2">多選三</asp:ListItem>
</asp:CheckBoxList>
<br />
<asp:DropDownList ID="DropDownList1" RepeatDirection="Horizontal" RepeatLayout="Flow"
runat="server">
<asp:ListItem Value="0">下拉選擇一</asp:ListItem>
<asp:ListItem Value="1">下拉選擇二</asp:ListItem>
<asp:ListItem Value="2">下拉選擇三</asp:ListItem>
</asp:DropDownList>
經(jīng)過(guò)瀏覽器解析后
<span id="RadioButtonList1">
<input id="RadioButtonList1_0" type="radio" name="RadioButtonList1" value="0" /><label for="RadioButtonList1_0">單選一</label>
<input id="RadioButtonList1_1" type="radio" name="RadioButtonList1" value="1" /><label for="RadioButtonList1_1">單選二</label>
<input id="RadioButtonList1_2" type="radio" name="RadioButtonList1" value="2" /><label for="RadioButtonList1_2">單選三</label>
</span>
<br />
<span id="CheckBoxList1">
<input id="CheckBoxList1_0" type="checkbox" name="CheckBoxList1$0" value="0" /><label for="CheckBoxList1_0">多選一</label>
<input id="CheckBoxList1_1" type="checkbox" name="CheckBoxList1$1" value="1" /><label for="CheckBoxList1_1">多選二</label>
<input id="CheckBoxList1_2" type="checkbox" name="CheckBoxList1$2" value="2" /><label for="CheckBoxList1_2">多選三</label>
</span>
<br />
<select name="DropDownList1" id="DropDownList1" RepeatDirection="Horizontal" RepeatLayout="Flow">
<option value="0">下拉選擇一</option>
<option value="1">下拉選擇二</option>
<option value="2">下拉選擇三</option>
</select>
對(duì)于這三個(gè)控件的操作無(wú)非就是取值和賦值,下面通過(guò)Jquery和.cs兩種方式進(jìn)行操作
Jquery對(duì)三種控件進(jìn)行操作
1、RadioButtonList
1)取值
$("#RadioButtonList1").change(function () {
//彈出選中項(xiàng)的val值
alert($("input[name='RadioButtonList1']:checked").val());
//彈出選中項(xiàng)的text值
alert($("input[name='RadioButtonList1']:checked+label").text())
});
2)賦值
//默認(rèn)選中第二項(xiàng)
var rbts = document.getElementsByName("RadioButtonList1");
for (var i = 0; i < rbts.length; i++) {
if (rbts[i].value == "1")
rbts[i].checked = "true";
}
2、DropDownList
1)取值
$("#DropDownList1").change(function () {
//彈出選中項(xiàng)的Val值
alert($("#DropDownList1").val());
//彈出選中項(xiàng)的text值
alert($("#DropDownList1 option:selected").text());
});
2)賦值
//默認(rèn)選中第二項(xiàng)
var ddls = $("#DropDownList1 option");
for (var i = 0; i < ddl.length; i++) {
if (ddl[i].value == "1") {
ddl[i].selected = "true";
}
}
3、CheckBoxList
1)取值
$("#CheckBoxList1 > input").click(function () {
var arrval = [];
var val = "";
$("#CheckBoxList1 :checkbox:checked").each(function () {
//將選中項(xiàng)的值放進(jìn)數(shù)組arrval
arrval.push($(this).val())
})
//將數(shù)組中的val值以‘,'進(jìn)行連接
val = arrval.join(',');
//彈出所有選擇的項(xiàng)以,連接
alert(val);
var arrtext = [];
var text = "";
$("#CheckBoxList1 :checkbox:checked").each(function () {
//將選中項(xiàng)的text值放進(jìn)arrtext數(shù)組中
arrtext.push($(this).next().html());
//將數(shù)組中的數(shù)據(jù)用,進(jìn)行連接
text = arrtext.join(",");
})
//彈出選中項(xiàng)的Text值
alert(text);
});
2)賦值
var cbks = $("#CheckBoxList1 input[type='checkbox']");
for (var i = 0; i < cbks.length; i++) {
if (cbks[i].value== "1"||cbks[i].value=="2") {
cbks[i].checked = "true";
}
}
- ASP.NET自定義Web服務(wù)器控件之Button控件
- asp.net Page.EnableEventValidation 屬性驗(yàn)證服務(wù)器控件的回發(fā)和回調(diào)事件出現(xiàn)的錯(cuò)誤
- jquery獲取ASP.NET服務(wù)器端控件dropdownlist和radiobuttonlist生成客戶(hù)端HTML標(biāo)簽后的value和text值
- asp.net 服務(wù)器控件的 ID,ClientID,UniqueID 的區(qū)別
- asp.net下使用Request.From獲取非服務(wù)器控件的值的方法
- jQuery生成asp.net服務(wù)器控件的代碼
- ASP.NET 動(dòng)態(tài)寫(xiě)入服務(wù)器端控件
- asp.net Page.Controls對(duì)象(找到所有服務(wù)器控件)
- Asp.Net使用服務(wù)器控件Image/ImageButton顯示本地圖片的方法
相關(guān)文章
asp.net正則表達(dá)式刪除指定的HTML標(biāo)簽的代碼
抓取某網(wǎng)頁(yè)的數(shù)據(jù)后(比如描述),如果照原樣顯示的話(huà),可能會(huì)因?yàn)樗锩姘瑳](méi)有閉合的HTML標(biāo)簽而打亂了格式,也可能它里面用了比較讓人 費(fèi)解 的HTML標(biāo)簽,把預(yù)訂的格式攪亂.2010-09-09關(guān)于Net6?Xunit?集成測(cè)試的問(wèn)題
這篇文章主要介紹了Net6?Xunit?集成測(cè)試的相關(guān)知識(shí),下面我將Net6下沒(méi)有使用Startup以及NET6以前版本使用Startup的集成測(cè)試(單元測(cè)試?yán)淄┳鲆粋€(gè)梳理,需要的朋友可以參考下2022-05-05ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺(tái)管理系統(tǒng)之前端頁(yè)面框架構(gòu)建源碼分享
這篇文章主要為大家分享了ASP.NET MVC4+EF5+EasyUI+Unity2.x注入的后臺(tái)管理系統(tǒng)之easyui前端頁(yè)面框架構(gòu)建源碼,感興趣的小伙伴們可以參考一下2016-07-07asp.net用三層實(shí)現(xiàn)多條件檢索示例
三層將項(xiàng)目分為界面層,業(yè)務(wù)邏輯層和數(shù)據(jù)訪(fǎng)問(wèn)層,下面為大家介紹下asp.net如何用三層實(shí)現(xiàn)多條件檢索,感興趣的朋友可以參考下2014-07-07ASP.NET Core實(shí)現(xiàn)多文件上傳
這篇文章介紹了ASP.NET Core實(shí)現(xiàn)多文件上傳的方法,文中通過(guò)示例代碼介紹的非常詳細(xì)。對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-01-01asp.net(c#)程序版本升級(jí)更新的實(shí)現(xiàn)代碼
我們做了程序,不免會(huì)有版本升級(jí),這就需要程序有自動(dòng)版本升級(jí)的功能。那么看看我是如何實(shí)現(xiàn)程序自動(dòng)更新的。2010-03-03推薦8項(xiàng)提高 ASP.NET Web API 性能的技術(shù)
ASP.NET Web API 是非常棒的技術(shù)。編寫(xiě) Web API 十分容易,以致于很多開(kāi)發(fā)者沒(méi)有在應(yīng)用程序結(jié)構(gòu)設(shè)計(jì)上花時(shí)間來(lái)獲得很好的執(zhí)行性能。2014-08-08