WebForm复合控件RadioButtonList、CheckBoxList、DropDownList
1、RadioButtonList 单选集合
-属性:RepeatDirection:Vertical (垂直排布)/Horizontal (横向排布)
RepeatLayout:Table (表格排布方式)/Flow (span排布方式)
RepeatColumns: 设置为多少列。

每一个单选按钮都是一个ListItem对象,他有 Enable(是否可用)、 selected(默认选中) Text(显示的文本) Value(隐藏的值)属性
赋值:两种数据绑定方法:
第一种: RadioButtonList1.DataSource=数据源集合
RadioButtonList1.DataValueField=""; //给程序看的
RadioButtonList1.DataTextField=""; //显示出来的
RadioButtonList1.DataBind(); //调用数据绑定方法
foreach(ListItem li in RadioButtonList1.Items )
{
if(li.value=="值")
li.Selected=true;
}
第二种:
List<UserNation> ulist =new UserNationData().SelectAll();
foreach(UserNation u in ulist)
{
ListItem li =new ListItem();
li.Text=u.NationName;
li.Value=u.NationCode;
if(li.Value=="值")
{ li.Selected=true; }
RadioButtonList.Item.Add(li);
}
取值:Label1.Text=RadioButtonList1.SelectedItem.Text+ RadioButtonList1.SelectedValue
2、CheckBoxList 复选集合

赋值和RadioButtonList 一样
取值:

注意!!!!!!!!!!!!!!!!!!
绑定数据出现数据选项无法更改
page_load事件再每一次页面刷新的时候都会执行
就会把数据重新绑定一次,再去执行按钮事件
判断页面是否是第一次加载还是响应回发
if(!ispostback)
{
只需要在页面第一次加载的时候才执行的代码写到这里面
注意95%的代码都要写到这里面
!事件委托不能写到这里面
}
3、DropDownList 下拉列表选择

赋值:

取值:

用DropDownList实现时间日期选择:
<asp:DropDownList ID="DropDownList1" runat="server"></asp:DropDownList>年
<asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>月
<asp:DropDownList ID="DropDownList3" runat="server"></asp:DropDownList>日
在C#后台代码加载时间日期
if (!IsPostBack)
{ //添加年月日
for (int i = DateTime.Now.Year; i >= ; i--)
{
ListItem li = new ListItem(i.ToString(), i.ToString());
DropDownList1.Items.Add(li);
}
for (int i = ; i < ; i++)
{
DropDownList2.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
for (int i = ; i <= ; i++)
{
DropDownList3.Items.Add(new ListItem(i.ToString(), i.ToString()));
}
}
在Js中写时间日期的限制
//年月日动态改变
//年份改变事件,如果是闰年,2月日期动态赋值;如果不是闰年,2月日期动态赋值
document.getElementById("DropDownList1").onchange = function () {
var year = document.getElementById("DropDownList1");
var mon = document.getElementById("DropDownList2");
var day = document.getElementById("DropDownList3");
if (mon.value == "") {
if (year.value % == && year.value % == || year.value % == ) { //先把天控件里的内容清除
day.options.length == ;
for (var i = ; i < ; i++) {
//创建一个option对象
var op = document.createElement("option");
//对象的value和显示的innerHTML都是i
op.value = i;
op.innerHTML = i;
//将对象放入天控件
day.appendChild(op); }
}
else {
day.options.length == ;
for (var i = ; i < ; i++) {
var op = document.createElement("option");
op.value = i;
op.innerHTML = i;
day.appendChild(op); }
}
} }
//月份改变事件:2月赋值,大月赋值,小月赋值。
document.getElementById("DropDownList2").onchange = function () {
var year = document.getElementById("DropDownList1");
var mon = document.getElementById("DropDownList2");
var day = document.getElementById("DropDownList3");
if (mon.value == "") {
if (year.value % == && year.value % == || year.value % == ) {
day.options.length == ;
for (var i = ; i < ; i++) {
var op = document.createElement("option");
op.value = i;
op.innerHTML = i;
day.appendChild(op); }
}
else {
day.options.length == ;
for (var i = ; i < ; i++) {
var op = document.createElement("option");
op.value = i;
op.innerHTML = i;
day.appendChild(op); } }
} else if (mon.value == "" || mon.value == "" || mon.value == "" || mon.value == "" || mon.value == "" || mon.value == "" || mon.value == "") {
day.options.length == ;
for (var i = ; i < ; i++) {
var op = document.createElement("option");
op.value = i;
op.innerHTML = i;
day.appendChild(op); }
}
else if (mon.value == "" || mon.value == "" || mon.value == "" || mon.value == "") {
day.options.length == ;
for (var i = ; i < ; i++) {
var op = document.createElement("option");
op.value = i;
op.innerHTML = i;
day.appendChild(op); }
} }
ps:自动提交的属性: AutoPostBack="True"
WebForm复合控件RadioButtonList、CheckBoxList、DropDownList的更多相关文章
- 【2017-05-19】WebForm复合控件、用DropDownList实现时间日期选择。
		
自动提交的属性: AutoPostBack="True" 1.RadioButtonList 单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...
 - webform 复合控件
		
RadioButtonList 单选按钮列表 属性:RepeatColumns 用于布局项的列数(每一行的个数) RepeatDirection 选择Vertical,纵向排列:选择Horizont ...
 - 【2017-05-19】WebForm复合控件
		
自动提交的属性: AutoPostBack="True" 1.RadioButtonList 单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...
 - Jquery 操作CheckBox ,RadioButtonList,DropDownList
		
Jquery版本2.1.4 CheckBox 1.获取值: $("#chb").prop("checked"); RadioButtonList 1.获取值: ...
 - WebForm控件之DropDownList
		
DropDwonList 三件事: ------------------------------------------1.把内容填进去-------------------------------- ...
 - WebForm使用JQuery实现DropDownList无刷新联动
		
目录(?)[-] 1 JS代码 2 页面相关控件用的是平台封装的控件普通DropDownList也可以 3 后台C代码 注意事项 原来用的微软封装的Ajax控件UpdatePannel和Scri ...
 - js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)
		
js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等) 欢迎访问原稿:http://hi.baidu.com/2wixia ...
 - 网站教学 提纲总结到ajax结束后面还有
		
Repeater - 重复器五个模板:HeaderTemplate - 在最上面,显示一次FooterTemplate - 最下面,显示一次ItemTemplate - 在中间,显示n次Alterna ...
 - C# 控件
		
.ascx:Web窗体用户控件.用来存放独立的用户控件,可提供众多页面使用: <%@ Control Language="C#" AutoEventWireup=" ...
 
随机推荐
- OpenGL着色器入门简介
			
说明:本文翻译自LearnOpengl经典教程,OpenGL着色器基础介绍的比较通俗易懂,特总结分享一下! 为什么要使用着色器?我们知道,OpenGL一般使用经典的固定渲染管线来渲染对象,但是随着Op ...
 - git使用git-credential-winstore保存https访问密码
			
使用 https 方式 clone 一个 git 仓库,每次pull 或者 push 的时候都需要输入用户名和密码. 访问远程Git仓库可以用 SSH 方式和 https 方式,https 每次访问时 ...
 - JS的eval函数解密反混淆
			
https://www.hhtjim.com/js-decryption-de-obfuscate-eval-function.html JS的eval函数解密反混淆
 - 【Zookeeper系列】ZooKeeper伸缩性(转)
			
原文地址:https://www.cnblogs.com/sunddenly/p/4143306.html 一.ZooKeeper中Observer 1.1 ZooKeeper角色 经过前面的介绍,我 ...
 - Javascript 异步处理与计时跳转
			
实现计时跳转的代码: <html lang="en"> <head> <meta charset="UTF-8"> < ...
 - CF886C Petya and Catacombs
			
题目描述 A very brave explorer Petya once decided to explore Paris catacombs. Since Petya is not really ...
 - ie9 remove出错  jquery SCRIPT5007: 缺少对象
			
针对IE11 remove不起作用的问题. 其中IE11.0.37也不支持 IE11.0.42支持可能是由于客户机器设置了兼容模式的原因. 因为里面包含了object元素,移除数据的时候发生的bug. ...
 - java awt 中文乱码 显示为 方块
			
今天调试同学的五子棋程序,同学的界面是用awt写的,运行的时候,发现菜单栏中的中文都无法正常显示,而是变为了一个个方框, 类似于这样:(图片来源于网络) 即使做了字体设置,比如设置为宋体,也还是无法正 ...
 - 【Linux内存源码分析】vmalloc不连续内存管理(转)
			
https://www.jeanleo.com/2018/09/09/%E3%80%90linux%E5%86%85%E5%AD%98%E6%BA%90%E7%A0%81%E5%88%86%E6%9E ...
 - PAT1018 Public Bike Management【dfs】【最短路】
			
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805489282433024 题意: 给定一个图,一个目的地和每个节 ...