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=" ...
随机推荐
- css如何实现一个元素高度固定宽度按比例显示?
用padding-top百分比可以实现宽度固定高度按比例展示,现在的需求是对一个video视频的盒子div高度是固定的,宽度如何按比例展示? 解决后效果如图: 红框标注的即是我在上面高度比例固定的范围 ...
- puppet(1)-简介
puppet: 开源的.新一代的集中化的配置管理工具: 目标状态 配置语言 Luke Kanies,puppet labs bootstrap --> configuration --> ...
- spring mvc接收ajax提交的JSON数据,并反序列化为对象
需求:spring mvc接收ajax提交的JSON数据,并反序列化为对象,代码如下: 前台JS代码: //属性要与带转化的对象属性对应 var param={name:'语文',price:16}; ...
- 【CF434E】Furukawa Nagisa's Tree 点分治
[CF434E]Furukawa Nagisa's Tree 题意:一棵n个点的树,点有点权.定义$G(a,b)$表示:我们将树上从a走到b经过的点都拿出来,设这些点的点权分别为$z_0,z_1... ...
- vmare 往 virtualbox迁移
vmare实在太卡了.抓狂. 于是想迁移到virtualbox观察下. 谷歌了下方案,发现众说纷纭. 有操作超级复杂的,比如:http://stackoverflow.com/questions/69 ...
- 解决ssh出现"Write failed: Broken pipe"问题
用 ssh 命令连接服务器之后,如果一段时间不操作,再次进入 Terminal 时会有一段时间没有响应,然后就出现错误提示: Write failed: Broken pipe 只能重新用 ssh 命 ...
- CString中 format、trimLeft和trimright、trim 和FindOneOf用法
1.format 可以帮助各种类型转换成CString. a. int 转 CString CString str; int number = 4; str.Format(_T("%d&qu ...
- myEclipse导入现成项目出现错误 【申明来源于网络】
myEclipse导入现成项目出现错误 [申明来源于网络] 原地址:http://blog.sina.com.cn/s/blog_6d7703400100znh6.html file–>impo ...
- 2018今日头条杯 E-Jump a Jump
Problem E. Jump A JumpInput file: standard inputOutput file: standard outputTime limit: 1 secondsMemor ...
- ZOJ 4067 - Books - [贪心][2018 ACM-ICPC Asia Qingdao Regional Problem J]
题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=4067 题意: 给出 $n$ 本书(编号 $1 \sim n$), ...