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. jaxb

    一.简介 JAXB(Java Architecture for XML Binding) 是一个业界的标准,是一项可以根据XML Schema产生Java类的技术.该过程中,JAXB也提供了将XML实 ...

  2. SQL 批量删除表

    /*-------------------------------- 功能说明: 批量DropTable 使用说明: 使用时一定要小心,因为删选表的where条件是like所有必须保证where 后的 ...

  3. MFC之进度条CProgressCtrl

    一.成员函数简介 1.create()针对不是通过资源文件上拖拉进度条控件生成的进度条,需要用此函数创建一个. 2.SetRange()设置进度条的起始值和终止值. 3.SetPos()设置进度条的当 ...

  4. gdbsever 使用说明

    gdbsever 使用说明 在新塘N3292x平台下 编译 gdbsever ./configure --target=arm-linux --host=arm-linux arm-linux-gdb ...

  5. rabbitmq 的心跳机制&应用

    官方文档说: If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) w ...

  6. css3美化复选框checkbox

     两种美化效果如下图: 代码(html) <div id="main"> <h2 class="top_title">使用CSS3美化复 ...

  7. PHP-----练习-------租房子-----增删改查,多条件查询

    练习-------租房子-----增删改查,多条件 一 .题目要求: 二 .做法: [1]建立数据库 [2]封装类文件------DBDA.class.php <?php class DBDA ...

  8. 问题:QXcbConnection: Could not connect to display

    Wkhtmltopdf 失败 (错误代码: -6). 消息: The switch --header-spacing, is not support using unpatched qt, and w ...

  9. jQuery的.bind()、.live()和.delegate()的区别

    参考:http://kb.cnblogs.com/page/94469/ 摘要:jQuery的.bind()..live()和.delegate()之间的区别并非总是那么明显的,然而,如果我们对所有的 ...

  10. VS2015 自动添加头部注释

    让VS自动生成类的头部注释,只需修改两个文集即可,一下两个路径下个有一个 Class.cs文件 D:\Program Files (x86)\Microsoft Visual Studio 14.0\ ...