单选框:RadioButton
GroupName:组名,如果要实现单选效果每个单选按钮的组名必须一样
是否被选中 RadioButton.checked 单选按钮列表:RadioButtonList
属性:RepeatDirection:Vertical上下 Honizontal左右
绑定数据源:
DataClassesDataContext context = new DataClassesDataContext();
RadioButtonList1.DataSource = context.Nation;
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataBind();
取选中项的值:
RadioButtonList1.SelectedValue.ToString();
设置哪一项被选中:
RadioButtonList1.SelectedIndex=; 复选框:CheckBox
是否被选中 CheckBox1.checked 复选框列表:CheckBoxList
属性:RepeatDirection:Vertical上下 Honizontal左右
绑定数据:
CheckBoxList1.DataSource = context.Nation;
CheckBoxList1.DataValueField = "Code";
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataBind();
取选中项的值:
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label1.Text += item.Text;
}
} 设置哪一项被选中:
如果是一项选中:SelectedIndex=;
如果是多想选中:
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Text == "汉族" || item.Text == "满族")
{
item.Selected = true;
}
} 练习:
全选: foreach (ListItem item in CheckBoxList1.Items)
{
item.Selected = CheckBox1.Checked;
} 弹窗:
string zhi="";
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
zhi += item.Value.ToString()+",";
}
}
//去掉最后多余的逗号
zhi = zhi.Substring(, zhi.Length - );
//拆分字符串
string[] codes;
codes = zhi.Split(',');
//造JS代码
string js = "<script type='text/javascript'>"; for (int i = ; i < codes.Length; i++)
{
js += "alert('" + codes[i] + "');";
}
js += "</script>"; Literal1.Text = js;
//Literal1.Text = "<script type='text/javascript'>alert('" + zhi + "')</script>";

最新文章

  1. 写个PHP框架吧
  2. DB2配置信息查看及其更新命令
  3. PHP dirname() 函数 __FILE__ __DIR__
  4. CSS、CSS2和CSS3选择器总结(全部选择器种类及其优先级)
  5. spring多数据源的配置
  6. PHP基础入门(一)---世界上最好用的编程语言
  7. Django源码学习 了解render与render_to_response
  8. PuTsangTo-单撸游戏开发03 碰撞与跳跃瑕疵版
  9. springboot添加swagger2组件
  10. api_request.go
  11. [Swift]LeetCode353. 设计贪吃蛇游戏 $ Design Snake Game
  12. linux_目录基本操作
  13. 关于Oracle RAC中SCN原理和机制的探索
  14. Angular简介与程序架构
  15. 关于session_cache_expire 的理解
  16. J2SE 8的Lambda --- 语法
  17. Sublime Text Build System——编译运行Java
  18. Crawl(2)
  19. springboot中使用JOIN实现关联表查询
  20. 迷你MVVM框架 avalonjs 1.2.5发布

热门文章

  1. hdu 3518 (后缀数组)
  2. cf
  3. Java使用ZXing生成二维码条形码
  4. 今天的学习——关于JS时间获取方面的小问题
  5. Oracle权限管理详解
  6. 如何在CentOS 7.x中安装OpenERP(Odoo)
  7. Maven配置中scope说明
  8. NSURLCache 和 NSCache 的区别
  9. JS日期的获取与加减
  10. 绑定hosts