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的更多相关文章

  1. 【2017-05-19】WebForm复合控件、用DropDownList实现时间日期选择。

    自动提交的属性: AutoPostBack="True" 1.RadioButtonList     单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...

  2. webform 复合控件

    RadioButtonList  单选按钮列表 属性:RepeatColumns 用于布局项的列数(每一行的个数) RepeatDirection 选择Vertical,纵向排列:选择Horizont ...

  3. 【2017-05-19】WebForm复合控件

    自动提交的属性: AutoPostBack="True" 1.RadioButtonList     单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...

  4. Jquery 操作CheckBox ,RadioButtonList,DropDownList

    Jquery版本2.1.4 CheckBox 1.获取值: $("#chb").prop("checked"); RadioButtonList 1.获取值: ...

  5. WebForm控件之DropDownList

    DropDwonList 三件事: ------------------------------------------1.把内容填进去-------------------------------- ...

  6. WebForm使用JQuery实现DropDownList无刷新联动

    目录(?)[-] 1  JS代码 2 页面相关控件用的是平台封装的控件普通DropDownList也可以 3 后台C代码 注意事项   原来用的微软封装的Ajax控件UpdatePannel和Scri ...

  7. js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等)

    js如何获取asp.net服务器端控件的值(label,textbox,dropdownlist,radiobuttonlist等) 欢迎访问原稿:http://hi.baidu.com/2wixia ...

  8. 网站教学 提纲总结到ajax结束后面还有

    Repeater - 重复器五个模板:HeaderTemplate - 在最上面,显示一次FooterTemplate - 最下面,显示一次ItemTemplate - 在中间,显示n次Alterna ...

  9. C# 控件

    .ascx:Web窗体用户控件.用来存放独立的用户控件,可提供众多页面使用: <%@ Control Language="C#" AutoEventWireup=" ...

随机推荐

  1. Springboot中如何在Utils类中使用@Autowired注入bean

    Springboot中如果希望在Utils工具类中,使用到我们已经定义过的Dao层或者Service层Bean,可以如下编写Utils类: 1. 使用@Component注解标记工具类Statisti ...

  2. Cuda9.1+cunn7.1+Tensorflow1.7-GUP

    Cuda9.1下载地址 cudnn下载  需要注册英伟达账号 cuda安装完成后默认的环境变量配置不对,CUDA_PATH是C:\Program Files\NVIDIA GPU Computing ...

  3. One example to understand SemFix: Program Repair via Semantic Analysis

    One example to understand SemFix: Program Repair via Semantic Analysis Basic Information Authors: Ho ...

  4. springboot 启动的时候报错 Error creating bean with name 'solrClient'

    springboot 启动的时候报错: org.springframework.beans.factory.BeanCreationException: Error creating bean wit ...

  5. docker参数注解

    # docker --help Usage: docker [OPTIONS] COMMAND [arg...] docker daemon [ --help | ... ] docker [ -h ...

  6. 13、cookie

    一.cookie: 1.cookie cookie的应用: 1.用户名密码 自动登录 2.购物车商品的保存. <1>缓存信息,只存储特定的重要的信息.程序编程完成.缓存信息cookie技术 ...

  7. 窗口,父窗口parentwindow,所有者窗口ownerwindow

    参考文档:http://www.cnblogs.com/fwycmengsoft/p/4026592.html 一. parent:创建者,owner:所有者 小玉的父母生下小玉,养到8岁,卖给贾府当 ...

  8. 有多个正整数存放在数组中,编写一个函数要求偶数在左边由小到大顺序放置,奇数在右边,也是由小到大顺序放置,Java实现

    思路: * 1.首先分左右 * 2.分好再排序(左边和右边都单独排序) 第一步:分左右 可得注意了: 大体思路最先是从两头出发分成4种情况讨论(左or右,奇数or偶数)循环处理,出口是双层的嵌套循环( ...

  9. mpdf中文开发使用文档附demo实例

    官网URL:http://www.mpdf1.com/mpdf/index.php github:https://github.com/mpdf/mpdf 官方开发手册,英文的:http://www. ...

  10. CentOS 7.6 安装 Weblogic 12

    http://download.oracle.com/otn/nt/middleware/12c/12213/fmw_12.2.1.3.0_wls_Disk1_1of1.zip java -jar f ...