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 复合控件的更多相关文章

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

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

  2. WebForm复合控件RadioButtonList、CheckBoxList、DropDownList

    1.RadioButtonList     单选集合 -属性:RepeatDirection:Vertical (垂直排布)/Horizontal (横向排布) RepeatLayout:Table ...

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

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

  4. Webform(简单控件、复合控件)

    一.简单控件: 1.label控件 <asp:Label ID="Label1" runat="server" Text="账 号:" ...

  5. webform简单、复合控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 2.Literal 空的,C#会把里 ...

  6. WebForm简单控件,复合控件

    简单控件: 1.Label 会被编译成span标签 属性: Text:文本内容 CssClass:CSS样式 Enlabled:是否可用 Visible:是否可见 __________________ ...

  7. WebForm 简单控件、复合控件

    简单控件: Label:被编译成span 样式表里设置lable的高度:  display:inline-block; Text  --文本 ForeColor  --字体颜色 Visible  -- ...

  8. WebForm 【复合控件】

    一 复合控件(取值,赋值用法相近)  RadioButtonList      --单选按钮 (一组列表)  <asp:RadioButtonList ID="RadioButtonL ...

  9. webform(复合控件)

    一.组合单选 RadioButtonList 单选按钮与简单控件不同,可理解为在集合中放置多对象 例: <asp:RadioButtonList ID="RadioButtonList ...

随机推荐

  1. @property 参数

    /* 1.set方法内存管理相关的参数 * retain : release旧值,retain新值(适用于OC对象类型) * assign : 直接赋值(默认,适用于非OC对象类型) * copy : ...

  2. linuxmint 17没有vim

    首先上软件管理器中安装vim,之后配置.vimrc文件 下面是从网上摘抄的配置文件: """""""""&qu ...

  3. Windows10更新提示语言不同不能保留程序和设置

    打开注册表编辑器(Win+R,输入regedit)定位到: HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Control\Nls\Language 在右边窗口中拉到最 ...

  4. AngularJS 配置和运行phonecat错误

    安装node.js 就按照入门上的步骤来就行了 第一步:下载安装node.js,并将程序路径添加到环境变量中PATH中 第二步:下载git版本控制软件 第三步:在git目录下点击git-bash.ex ...

  5. 【Eclipse】总结自己在工作中经常使用到的Eclipse快捷键

    一些我觉得比较有用的快捷键,仅作参考. 1.alt + shift + c :更改方法签名. 2.三次鼠标左键单击: 选中一整行. 3.alt + shift + d/x: 再按t : 运行junit ...

  6. 在虚拟机下安装hadoop集成环境(centos7+hadoop-2.6.4+jdk-7u79)

    [1]64为win7系统,用virtualbox建立linux虚拟机时,为什么没有64位的选项? 百度 [2]在virtualbox上安装centos7 [3]VirtualBox虚拟机网络环境解析和 ...

  7. C++中的 :: 用法

    ::是运算符中等级最高的,它分为三种:1)global scope(全局作用域符),用法(::name)2)class scope(类作用域符),用法(class::name)3)namespace ...

  8. tc674div1b

    题意:给出n个孩子的初始位置,和每个孩子开始的朝向(左或者右),然后孩子的行走规则是,速度始终为1,两人相遇则两人立即转身背向而行. 现在有q次询问,每次问编号为i的孩子在时间t距离原点的距离.返回所 ...

  9. CI 笔记一

    CodeIgniter 说明 CodeIgniter 是为PHP 开发人员提供的一套Web 应用程序工具包.它的目标是能 够让你比从零开始更加快速的完成项目,它提供了一套丰富的的类库来满足我们日常 的 ...

  10. 在linux中减小和增大LV的过程与思考

    今天在安装oracle 11 rac的时候,查看操作系统df -lh,发现/home目录竟然分了500多G,/根目录才有50G,当时我就爆了句粗口,这TM系统是怎么做的. Filesystem     ...