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 ...
随机推荐
- Sizzle选择器引擎介绍
一.前言 Sizzle原来是jQuery里面的选择器引擎,后来逐渐独立出来,成为一个独立的模块,可以自由地引入到其他类库中.我曾经将其作为YUI3里面的一个module,用起来畅通无阻,没有任何障碍. ...
- C# 发送电子邮件
网上找到的发送邮件的类,改了一点点,在此谢谢原作者的奉献. 1.源码: public class CSendMail { private MailMessage mailMessage; privat ...
- MyEclispe发布web项目-遁地龙卷风
(-1)写在前面 我用的是MyEclipse8.5. 还记得以前帮助一个女同学解决问题的时候,特意情调了要先启动服务在发布项目,其实单独的时候都是知道的,总和起来后就容易片面的给出结论.因为不会发生问 ...
- css如何实现水平居中呢?css实现水平居中的方法?
面试中遇到的一个问题:如何让css实现水平居中?下面来看一下哪些方法能实现水平居中. 首先分两种情况,行内元素还是块级元素.然而块级元素又分为定宽块状元素和不定款块状元素.先来看下行内元素如何水平居中 ...
- redmine问题集锦
当我新建LDAP认证模式时,遇到如下错误:
- Qt5.7中使用MySQL Driver
Qt5.7中使用MySQL Driver 1.使用环境 Qt5.7的安装安装就已经带了MySQL Driver,只需要在安装的时候选择一下即可. 如果没有安装,可以采取自己编译的方式. 在Qt的源码包 ...
- linux网络配置
VMware下,centos系统,安装好后,一直连不上外网.在网上查了好多资料,都没有找到解决的办法.最后,把自己的解决方案,写到下面. 其中ipaddr是window下vmnet8的ip地址,在do ...
- ++i vs i++
[分析] i++与++i哪个效率更高? (1)在内建数据类型的情况下,效率没有区别: (2)在自定义数据类型Class的情况下,++i效率更高! 自定义数据类型的情况下:++i返回对象的引用:i++总 ...
- monkeyrunner API接口文档内容
用python编写脚本 1.导入模块: MonkeyRunner MonkeyDevice MonkeyImage ps:如果给导入模块起别名,就应该使用别名,而不能使用原名,否则会出现错误. f ...
- linux升级openssh
升级sshd到OpenSSH-6.7并删除老版本ssh 1)升级前准备 查看是否缺包 # rpm -qa | egrep "gcc|make|perl|pam|pam-devel" ...