12.16单选框,复选框
2015-12-16 08:55
351 查看
1:单选框 RadioButton
属性: GroupName 组名 想要产生互斥效果:将GroupName设置成统一名字
看是否选中: bool sex = RadioButton1.Checked;
Label1.Text = sex.ToString();
/ /选中
bool sex = RadioButton1.Checked;
//Label1.Text = sex.ToString();
if (sex == true)
{ Label1.Text = "女"; }
else
{
Label1.Text = "男";
}
2:单选按钮列表: RadioButtonList
看是否选中: bool sex = RadioButton1.Checked;
绑定数据:
if (!IsPostBack)
{
NationDataContext context = new NationDataContext();
RadioButtonList1.DataSource = context.Nation;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataBind();
}
取选中项的值:
Label2.Text = RadioButtonList1.SelectedValue.ToString();
设置那一项被选中;
只能设置一项被选中:RadioButtonList1.SelectedIndex = 1;
3:复选框:checkbox
4:复选框列表
属性:repeatdrection:项的布局方向
看是否选中: bool sex = CheckBoxList1.Checked;
绑定数据:
if (!IsPostBack)
{
NationDataContext context = new NationDataContext();
CheckBoxList1.DataSource = context.Nation;
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "Code";
CheckBoxList1.DataBind();
}
取选中项的值:
protected void Button3_Click(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label3.Text += item.Text;
}
}
s设置哪项选中:
如果设置一项选中:checkBoxlist.selectedindex=2;
如果设置多项被选中:
protected void Button3_Click(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label3.Text += item.Value;//显示编号code
Label4.Text += item.Text;//显示民族name
}
}
练习,全选,有弹窗
1:全部选中一次弹出
protected void Button1_Click(object sender, EventArgs e)
{
string zhi = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
zhi += item.Value.ToString()+",";
}
}
//去掉最后一个逗号,阿贾克斯必须去掉
zhi = zhi.Substring(0,zhi.Length-1);
//Literal1.Text = "<script type='text/javascript'> alert('"+zhi+"')</script>";//全部选中 实现弹窗=
}
}
2 选中后,按照选中的号码一个一个的弹出
protected void Button1_Click(object sender, EventArgs e)
{
string zhi = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
zhi += item.Value.ToString()+",";
}
}
//去掉最后一个逗号,阿贾克斯必须去掉
zhi = zhi.Substring(0,zhi.Length-1);
//Literal1.Text = "<script type='text/javascript'> alert('"+zhi+"')</script>";//全部选中 实现弹窗=
//拆分字符串
string[] Codes;
Codes= zhi.Split(',');
//造js代码
string js = "<script type='text/javascript'>";
for(int i=0;i< Codes.Length;i++ )
{
js+="alert('"+Codes[i]+"');";
}
js += "</script>";
Literal1.Text = js;
}
属性: GroupName 组名 想要产生互斥效果:将GroupName设置成统一名字
看是否选中: bool sex = RadioButton1.Checked;
Label1.Text = sex.ToString();
/ /选中
bool sex = RadioButton1.Checked;
//Label1.Text = sex.ToString();
if (sex == true)
{ Label1.Text = "女"; }
else
{
Label1.Text = "男";
}
2:单选按钮列表: RadioButtonList
看是否选中: bool sex = RadioButton1.Checked;
绑定数据:
if (!IsPostBack)
{
NationDataContext context = new NationDataContext();
RadioButtonList1.DataSource = context.Nation;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataBind();
}
取选中项的值:
Label2.Text = RadioButtonList1.SelectedValue.ToString();
设置那一项被选中;
只能设置一项被选中:RadioButtonList1.SelectedIndex = 1;
3:复选框:checkbox
4:复选框列表
属性:repeatdrection:项的布局方向
看是否选中: bool sex = CheckBoxList1.Checked;
绑定数据:
if (!IsPostBack)
{
NationDataContext context = new NationDataContext();
CheckBoxList1.DataSource = context.Nation;
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "Code";
CheckBoxList1.DataBind();
}
取选中项的值:
protected void Button3_Click(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label3.Text += item.Text;
}
}
s设置哪项选中:
如果设置一项选中:checkBoxlist.selectedindex=2;
如果设置多项被选中:
protected void Button3_Click(object sender, EventArgs e)
{
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label3.Text += item.Value;//显示编号code
Label4.Text += item.Text;//显示民族name
}
}
练习,全选,有弹窗
1:全部选中一次弹出
protected void Button1_Click(object sender, EventArgs e)
{
string zhi = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
zhi += item.Value.ToString()+",";
}
}
//去掉最后一个逗号,阿贾克斯必须去掉
zhi = zhi.Substring(0,zhi.Length-1);
//Literal1.Text = "<script type='text/javascript'> alert('"+zhi+"')</script>";//全部选中 实现弹窗=
}
}
2 选中后,按照选中的号码一个一个的弹出
protected void Button1_Click(object sender, EventArgs e)
{
string zhi = "";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
zhi += item.Value.ToString()+",";
}
}
//去掉最后一个逗号,阿贾克斯必须去掉
zhi = zhi.Substring(0,zhi.Length-1);
//Literal1.Text = "<script type='text/javascript'> alert('"+zhi+"')</script>";//全部选中 实现弹窗=
//拆分字符串
string[] Codes;
Codes= zhi.Split(',');
//造js代码
string js = "<script type='text/javascript'>";
for(int i=0;i< Codes.Length;i++ )
{
js+="alert('"+Codes[i]+"');";
}
js += "</script>";
Literal1.Text = js;
}
相关文章推荐
- js完美验证身份证号,邮箱,手机号
- android.graphics.Matrix详解
- 开源企业IM-免费企业即时通讯-ENTBOOST V2014.183 Windows版本号正式宣布
- MYSQL 根据逗号拆分字段
- 使用“cmd /c start”时遇到路径中含有空格的解决方法
- [leetcode] 53. Maximum Subarray 解题报告
- sql实例:成绩排名,日期函数及格式转换
- 关于Android 传感器坐标与读数的进一步讨论
- 《1024伐木累》- 老王请客吃晚饭,介绍对象
- AngularJs parent index
- 【DT】笔记
- Uber 究竟使用什么开发语言?
- 滴滴快车奖励政策,高峰奖励,翻倍奖励,按成交率,指派单数分级(12月16日)
- 电商、微商、O2O 门槛从来就不低
- 详解JavaScript基于面向对象之继承实例
- 使用Feeds excel 导入的方法
- Android实战 - 音心播放器 (通知实现音乐的播放/暂停/下一曲控制)
- While reading /Users/cola/Desktop/csun first 2/Res/Quasar/Quasar_Tex_Up.png pngcrush caught libpng
- 原 ajax.googleapis.com等公共库加载被“墙”的解决方法!
- Android 模拟器设置