单选框:RadioButton
属性:GroupName:组名,如果要实现单选效果,每个单选按钮的组名必须一样
看一下该按钮是否选中:RadioButton1.Checked;
单选按钮列表:RadioButtonList
属性:RepeatDirection:横向或纵向
绑定数据:
RadioButtonList1.DataSource = context.Nation;
RadioButtonList1.DataTextField = "Name";
RadioButtonList1.DataValueField = "Code";
RadioButtonList1.DataBind();
取选中项的值:
RadioButtonList1.SelectedValue.ToString();
设置哪一项被选中:
RadioButtonList1.SelectedIndex = 2;
复选框:CheckBox
看一下该按钮是否选中:checkbox1.Checked;
复选框列表:CheckBoxList
属性RepeatDirection:横向或纵向
绑定数据:
CheckBoxList1.DataSource = context.Nation;
CheckBoxList1.DataTextField = "Name";
CheckBoxList1.DataValueField = "Code";
CheckBoxList1.DataBind();
取选中项的值:
foreach (ListItem item in CheckBoxList1.Items)
{
if (item.Selected)
{
Label1.Text += item.Text;
}
}
设置哪项选中:
如果设置一项选中:SelectedIndex = 2;
如果设置多项选中:foreach()