webform 复合控件
RadioButtonList 单选按钮列表
属性:RepeatColumns 用于布局项的列数(每一行的个数)
RepeatDirection 选择Vertical,纵向排列;选择Horizontal,横向排列。
RepeatLayout 选择Table,RadioButtonList用<table>布局;
选择Flow,RadioButtonList用<span>布局;
选择OrderedList时RepeatDirection 属性必须选择Vertical,RadioButtonList用<ol>有序排列布局;
选择UnorderedList时RepeatDirection 属性必须选择Vertical,RadioButtonList用<ul>无序排列布局;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
List<Class1> clist = new List<Class1>();
Class1 C1 = new Class1() { Code = "", Name = "张店" };
Class1 C2 = new Class1() { Code = "", Name = "淄川" };
Class1 C3 = new Class1() { Code = "", Name = "博山" };
Class1 C4 = new Class1() { Code = "", Name = "临淄" };
Class1 C5 = new Class1() { Code = "", Name = "周村" };
Class1 C6 = new Class1() { Code = "", Name = "桓台" };
Class1 C7 = new Class1() { Code = "", Name = "高青" };
Class1 C8 = new Class1() { Code = "", Name = "沂源" };
clist.Add(C1);
clist.Add(C2);
clist.Add(C3);
clist.Add(C4);
clist.Add(C5);
clist.Add(C6);
clist.Add(C7);
clist.Add(C8);
//绑定数据
RadioButtonList1.DataSource = clist;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataBind();//将绑定的数据调用到控件*很重要* //设置默认选中项
RadioButtonList1.SelectedIndex = ;//默认第一个
// RadioButtonList1.SelectedIndex = clist.Count - 1;//默认最后一个
//RadioButtonList1.SelectedValue = "002";//默认选中项的Code为002 //根据Name选择默认选中项
//foreach(ListItem li in RadioButtonList1.Items)
//{
// if(li.Text=="桓台")
// {
// li.Selected = true;
// }
//}
}
Button1.Click += Button1_Click;
} void Button1_Click(object sender, EventArgs e)
{
Label1.Text = RadioButtonList1.SelectedValue;//取出Value值
Label1.Text = RadioButtonList1.SelectedItem.Text;//取出Text值
}
1、绑定数据:
RadioButtonList1.DataSource = clist;
RadioButtonList1.DataTextField = "Name";//显
RadioButtonList1.DataValueField = "Code";//隐
RadioButtonList1.DataBind();//将绑定的数据调用到控件*很重要*
2、设置选中项:
//根据索引设置
RadioButtonList1.SelectedIndex = ;//默认第一个
RadioButtonList1.SelectedIndex = clist.Count - ;//默认最后一个
//根据Value值设置
RadioButtonList1.SelectedValue = "";//默认选中项的Code为002 //根据Text值设置
foreach (ListItem li in RadioButtonList1.Items)
{
if (li.Text == "桓台")
{
li.Selected = true;
}
}
3、取出数据:
Label1.Text = RadioButtonList1.SelectedValue;//取出Value值
Label1.Text = RadioButtonList1.SelectedItem.Text;//取出Text值
3 Label1.Text = RadioButtonList1.SelectedItem.Selected.ToString();//获取一个值判定是否被选中
CheckBoxList:复选框列表
属性:RepeatColumn、RepeatDirection 和RepeatLayout 同RadioButtonList的使用方式相同;
1、绑定数据:
CheckBoxList1.DataSource = clist;
CheckBoxList1.DataTextField = "Name";//显
CheckBoxList1.DataValueField = "Code";//隐
CheckBoxList1.DataBind();//将绑定的数据调用到控件*很重要*
2、设置选中项:
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Text == "桓台")
{
li.Selected = true;
}
if (li.Text == "张店")
{
li.Selected = true;
}
}
3、取出数据:
//取一个数据:
Label1.Text = CheckBoxList1.SelectedItem.Text;
//取一堆数据:
foreach (ListItem li in CheckBoxList1.Items)
{
if (li.Selected == true)
{
Label1.Text += li.Text+",";
}
}
DropDownList:下拉列表
1、绑定数据
DropDownList1.DataSource = clist;
DropDownList1.DataTextField = "Name";
DropDownList1.DataValueField = "Code";
DropDownList1.DataBind();
2、设置选中项
//根据索引设置
DropDownList1.SelectedIndex = ;
DropDownList1.SelectedIndex = clist.Count - ;//默认最后一个
//根据Value值设置
DropDownList1.SelectedValue = "";//默认选中项的Code为002 //根据Text值设置
foreach (ListItem li in DropDownList1.Items)
{
if (li.Text == "桓台")
{
li.Selected = true;
}
}
3、取出数据
1 Label1.Text = DropDownList1.SelectedValue;//取出Value值
Label1.Text = DropDownList1.SelectedItem.Text;//取出Text值
Label1.Text = DropDownList1.SelectedItem.Selected.ToString();//获取一个值判定是否被选中
ListBox 复选列表
属性: SelectionMode 列表选择模式: Single 单选;Multiple多选
绑定数据,设置选中项,取出数据方法同CheckBoxList相同。
webform 复合控件的更多相关文章
- 【2017-05-19】WebForm复合控件
自动提交的属性: AutoPostBack="True" 1.RadioButtonList 单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...
- WebForm复合控件RadioButtonList、CheckBoxList、DropDownList
1.RadioButtonList 单选集合 -属性:RepeatDirection:Vertical (垂直排布)/Horizontal (横向排布) RepeatLayout:Table ...
- 【2017-05-19】WebForm复合控件、用DropDownList实现时间日期选择。
自动提交的属性: AutoPostBack="True" 1.RadioButtonList 单选集合 -属性:RepeatDirection:Vertical (垂直排布 ...
- Webform(简单控件、复合控件)
一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...
- webform简单、复合控件
简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 2.Literal 空的,C#会把里 ...
- WebForm简单控件,复合控件
简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 __________________ ...
- WebForm 简单控件、复合控件
简单控件: Label:被编译成span 样式表里设置lable的高度: display:inline-block; Text --文本 ForeColor --字体颜色 Visible -- ...
- WebForm 【复合控件】
一 复合控件(取值,赋值用法相近) RadioButtonList --单选按钮 (一组列表) <asp:RadioButtonList ID="RadioButtonL ...
- webform(复合控件)
一.组合单选 RadioButtonList 单选按钮与简单控件不同,可理解为在集合中放置多对象 例: <asp:RadioButtonList ID="RadioButtonList ...
随机推荐
- ios几个重要方法
加载类到内存,程序刚启动的时候调用,调用在main函数之前 1.+(void)load{ } 初始化类,类第一次使用的时候调用一次 2.+(void)initialize{ } 控制器的视图架构,设 ...
- tyvj1194 划分大理石
描述 有价值分别为1..6的大理石各a[1..6]块,现要将它们分成两部分,使得两部分价值之和相等,问是否可以实现.其中大理石的总数不超过20000. 输入格式 有多组数据!所以可能有多行如果有0 ...
- R语言-用R眼看琅琊榜小说的正确姿势
博客总目录:http://www.cnblogs.com/weibaar/p/4507801.html 目录: 零:写在前面的一些废话 一.R眼看琅琊榜的基本原理 1.导入数据 2.筛选数据 3.多条 ...
- 【PHP发展史】PHP5.2 到 PHP5.6 中新增的功能详解
截至目前(2014.2), PHP 的最新稳定版本是 PHP5.5, 但有差不多一半的用户仍在使用已经不在维护的 PHP5.2, 其余的一半用户在使用 PHP5.3. 因为 PHP 那“集百家之长”的 ...
- 【Alpha】Daily Scrum Meeting第一次
一.本次Daily Scrum Meeting主要内容 代码任务细分 服务器搭建 每个人时间分配及安排 二.项目进展 学号尾数 今天做的任务 任务完成度 明天要做的任务 612 写代码框架 30% 主 ...
- C和指针 第五章 逻辑位移与算术位移
对于操作数的左位移都是相同的,右边空出来的位置用0补齐. 但是对于右位移,对于有符号和无符号数是不一样的,最高位的1有两种处理方式.逻辑位移和算术位移. 逻辑位移:右移入位用0补齐 算术位移:右移入位 ...
- BZOJ2007——[Noi2010]海拔
1.题意:一个裸的最小割 2.分析:直接转成对偶图最短路就好了,水爆了!(雾) #include <queue> #include <cstdio> #include < ...
- python之路五
内建模块 time和datetime 在Python中,通常有这几种方式来表示时间:1)时间戳 2)格式化的时间字符串 3)元组(struct_time)共九个元素.由于Python的time模块实现 ...
- centos7.0安装后ifconfig无法使用
由于使用的最小化安装,需要安装net-tools 输入如下命令: #yum install -y net-tools 即可
- 【krpano】汉化Web VR设置界面
欢迎加入qq群551278936讨论krpano解密技术以及获取最新软件 krpano 1.19支持了Web VR功能,允许以VR的方式查看全景图,配合上VR设备可以实现VR效果. 在VR方式查看时, ...