<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Text="值1" Value="信息1" Selected="True" Enabled="false" />
<asp:ListItem Text="值2" Value="信息2" />
<asp:ListItem Text="值3" Value="信息3" />
</asp:RadioButtonList>
<!--单选按钮组,Selected为选中按钮,Enabled是否禁用,Value传递的隐藏值-->
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="列1" DataValueField="列2" AppendDataBoundItems="true">
<asp:ListItem Text="提示选项是什么" Value=""/>
</asp:DropDownList>
<!--列表项控件,DataTextField为列表展现的事物,DataValueField为传递的隐藏值,也可能是键值
DataSourceID是关联连接数据库的id,AppendDataBoundItems添加一个默认,即 <asp:ListItem>
如果缺少的话,默认的项会改变所有-->
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select 列1,列2 from 练习表"
ConnectionString="<%ConnectionString:练习表 %>"></asp:SqlDataSource>
<!--连接并查询数据库,从练习表中查询列1和列2,ConnectionString表连接数据库的具体方法,在web.config
中的文件为<connectionStrings><add name="练习表" connectionString="Data Source=localhost;
Initial Catalog=xuesheng; Integrated Security=True"providerName="System.Data.SqlClient"/>
</connectionStrings>添加到<configuration>中间,这是采用声明绑定-->
<asp:RadioButtonList ID="RadioButtonList2" runat="server" RepeatColumns="3"></asp:RadioButtonList>
<!--此控件同DropDownList差不多,一次只能选择一个,有一个为一行显示多少个RepeatColumns-->
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<!--同上面一样的,只不过他可以一次选择多个选项-->
<asp:BulletedList ID="BulletedList1" runat="server" BulletImageUrl="添加的小标志"></asp:BulletedList>
<!--可以在选项前添加一个标志BulletImageUrl,他不支持 selectedindex:selecteditem:selectedvalue:-->
<asp:ListBox ID="ListBox2" runat="server" DataTextField="miaoshu" DataValueField="id"></asp:ListBox>
<!-- public class fangfa
{
private int _id;
public int id //传递给DataValueField
{
get { return _id; }
}
private string _miaoshu;
public string miaoshu //传递给DataTextField
{
get { return _miaoshu; }
}
public fangfa(int Id,string Miaoshu)//创建一个构造函数
{
_id = Id;
_miaoshu = Miaoshu;
}
if (!IsPostBack) //在page_Load中添加
{
List<fangfa> shili = new List<fangfa>();//实例化一个集合
shili.Add(new fangfa(1, "一个"));
shili.Add(new fangfa(2, "两个"));
shili.Add(new fangfa(3, "三个"));//添加东西
ListBox1.DataSource = shili;
ListBox1.DataBind();//把集合绑定到ListBox1中
}
} 这种是编程式绑定-->
</div>
他们都具有
selectedindex:获取或设置被选中项目的索引值;
selecteditem:获取被选中的项目;
selectedvalue:获取或设置被选中项目的值。
<asp:ListItem Text="值1" Value="信息1" Selected="True" Enabled="false" />
<asp:ListItem Text="值2" Value="信息2" />
<asp:ListItem Text="值3" Value="信息3" />
</asp:RadioButtonList>
<!--单选按钮组,Selected为选中按钮,Enabled是否禁用,Value传递的隐藏值-->
<asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource1"
DataTextField="列1" DataValueField="列2" AppendDataBoundItems="true">
<asp:ListItem Text="提示选项是什么" Value=""/>
</asp:DropDownList>
<!--列表项控件,DataTextField为列表展现的事物,DataValueField为传递的隐藏值,也可能是键值
DataSourceID是关联连接数据库的id,AppendDataBoundItems添加一个默认,即 <asp:ListItem>
如果缺少的话,默认的项会改变所有-->
<asp:SqlDataSource ID="SqlDataSource1" runat="server" SelectCommand="select 列1,列2 from 练习表"
ConnectionString="<%ConnectionString:练习表 %>"></asp:SqlDataSource>
<!--连接并查询数据库,从练习表中查询列1和列2,ConnectionString表连接数据库的具体方法,在web.config
中的文件为<connectionStrings><add name="练习表" connectionString="Data Source=localhost;
Initial Catalog=xuesheng; Integrated Security=True"providerName="System.Data.SqlClient"/>
</connectionStrings>添加到<configuration>中间,这是采用声明绑定-->
<asp:RadioButtonList ID="RadioButtonList2" runat="server" RepeatColumns="3"></asp:RadioButtonList>
<!--此控件同DropDownList差不多,一次只能选择一个,有一个为一行显示多少个RepeatColumns-->
<asp:CheckBoxList ID="CheckBoxList1" runat="server"></asp:CheckBoxList>
<!--同上面一样的,只不过他可以一次选择多个选项-->
<asp:BulletedList ID="BulletedList1" runat="server" BulletImageUrl="添加的小标志"></asp:BulletedList>
<!--可以在选项前添加一个标志BulletImageUrl,他不支持 selectedindex:selecteditem:selectedvalue:-->
<asp:ListBox ID="ListBox2" runat="server" DataTextField="miaoshu" DataValueField="id"></asp:ListBox>
<!-- public class fangfa
{
private int _id;
public int id //传递给DataValueField
{
get { return _id; }
}
private string _miaoshu;
public string miaoshu //传递给DataTextField
{
get { return _miaoshu; }
}
public fangfa(int Id,string Miaoshu)//创建一个构造函数
{
_id = Id;
_miaoshu = Miaoshu;
}
if (!IsPostBack) //在page_Load中添加
{
List<fangfa> shili = new List<fangfa>();//实例化一个集合
shili.Add(new fangfa(1, "一个"));
shili.Add(new fangfa(2, "两个"));
shili.Add(new fangfa(3, "三个"));//添加东西
ListBox1.DataSource = shili;
ListBox1.DataBind();//把集合绑定到ListBox1中
}
} 这种是编程式绑定-->
</div>
他们都具有
selectedindex:获取或设置被选中项目的索引值;
selecteditem:获取被选中的项目;
selectedvalue:获取或设置被选中项目的值。