复选列表(CheckBoxList)/单选列表(RadioButtonList)
2009-01-07 18:39
399 查看
CheckBoxList(复选列表)
1.如何自己添加项
2.布局方式(水平/垂直)(表格/流)(文字和框的位置)
3.读取数据库的内容
4.为数据绑定再追加一个静态项(比如“不选择”静态项目)注意行为里的AppendDataBoundItems属性
5.控件事件
6.读出被选中的
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
int n = CheckBoxList1.Items.Count;
for (int i = 0; i < n;i++ )
{
if (CheckBoxList1.Items[i].Selected)
{
string txt = CheckBoxList1.Items[i].Text;
string t = txt.Replace("aidd2008","火君道人");
Response.Write(t); //CheckBoxList1的AutoPostBack?
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBoxList1.RepeatDirection == RepeatDirection.Vertical)
{
CheckBoxList1.RepeatDirection = RepeatDirection.Horizontal;
Button1.Text = "给我垂直排列";
}
else
{
CheckBoxList1.RepeatDirection = RepeatDirection.Vertical;
Button1.Text = "给我水平排列";
}
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
int n = CheckBoxList1.Items.Count;
for (int i = 0; i < n; i++)
{
CheckBoxList1.Items[i].Text = CheckBoxList1.Items[i].Text + i;
}
}
}
<form id="form1" runat="server">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="senduser" DataValueField="id" OnDataBound="CheckBoxList1_DataBound"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>不选择</asp:ListItem>
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:2000data %>"
SelectCommand="SELECT TOP 5 id, filenames, senduser FROM redheadedfile"></asp:SqlDataSource>
<p />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="排列" />
</form>
<connectionStrings>
<add name="2000data" connectionString="Data Source=.;Initial Catalog=data;Persist Security Info=True;User ID=i05;Password=i05630229" providerName="System.Data.SqlClient" />
</connectionStrings>
RadioButtonList(单选列表)
与CheckBoxList(复选列表)不同的是,单选列表是单选,复选列表是可以复选
1.如何自己添加项
2.布局方式(水平/垂直)(表格/流)(文字和框的位置)
3.读取数据库的内容
4.为数据绑定再追加一个静态项(比如“不选择”静态项目)注意行为里的AppendDataBoundItems属性
5.控件事件
6.读出被选中的
using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
public partial class Default4 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
int n = CheckBoxList1.Items.Count;
for (int i = 0; i < n;i++ )
{
if (CheckBoxList1.Items[i].Selected)
{
string txt = CheckBoxList1.Items[i].Text;
string t = txt.Replace("aidd2008","火君道人");
Response.Write(t); //CheckBoxList1的AutoPostBack?
}
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (CheckBoxList1.RepeatDirection == RepeatDirection.Vertical)
{
CheckBoxList1.RepeatDirection = RepeatDirection.Horizontal;
Button1.Text = "给我垂直排列";
}
else
{
CheckBoxList1.RepeatDirection = RepeatDirection.Vertical;
Button1.Text = "给我水平排列";
}
}
protected void CheckBoxList1_DataBound(object sender, EventArgs e)
{
int n = CheckBoxList1.Items.Count;
for (int i = 0; i < n; i++)
{
CheckBoxList1.Items[i].Text = CheckBoxList1.Items[i].Text + i;
}
}
}
<form id="form1" runat="server">
<asp:CheckBoxList ID="CheckBoxList1" runat="server" AppendDataBoundItems="True" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="senduser" DataValueField="id" OnDataBound="CheckBoxList1_DataBound"
OnSelectedIndexChanged="CheckBoxList1_SelectedIndexChanged">
<asp:ListItem>不选择</asp:ListItem>
</asp:CheckBoxList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:2000data %>"
SelectCommand="SELECT TOP 5 id, filenames, senduser FROM redheadedfile"></asp:SqlDataSource>
<p />
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="排列" />
</form>
<connectionStrings>
<add name="2000data" connectionString="Data Source=.;Initial Catalog=data;Persist Security Info=True;User ID=i05;Password=i05630229" providerName="System.Data.SqlClient" />
</connectionStrings>
RadioButtonList(单选列表)
与CheckBoxList(复选列表)不同的是,单选列表是单选,复选列表是可以复选
相关文章推荐
- vs2005入门 之 单选列表(CheckBoxList)和复选列表(RadioButtonList)[视频]
- ASP.NET中 RadioButtonList(单选按钮组),CheckBoxList(复选框组),DropDownList(下拉框),ListBox(列表框),BulletedList(无序列表)的使用前台绑定
- Silverlight中利用ListBox特性实现单选按钮组RadioButtonList和复选按钮组CheckBoxList的功能
- CheckBox(复选按钮)/RadioButton(单选按钮)/BulletedList控件
- jquery.validator 验证CheckBoxList,RadioButtonList,DropDownList
- 使用复杂绑定完成 CheckBoxList 和 RadioButtonList 控件的绑定
- Android UI 详解之单选(RadioButton)和复选(CheckBox)
- ASP.NET服务器端控件RadioButtonList,DropDownList,CheckBoxList的取值、赋值用法
- Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中
- Android简单对话框、输入对话框、单选对话框、复选对话框、列表对话框、自定义对话框、时间对话框
- DataGrid中加入CheckBox,并实现单选 选择自 listhome 的 Blog
- Jquery.Validate验证CheckBoxList,RadioButtonList,DropDownList是否选中
- 设定下拉列表控件DropDownList,复选按钮CheckBox,RadioButton默认值总结测试
- [我的ASP.net学习历程]CheckBoxList和RadioButtonList的数据梆定
- 单选CheckBoxList
- Js中得到radiobuttonlist 和CheckBoxList 的值
- Chapter 2. ASP.NET 标准控件(单选、复选、列表、面板、日历)
- MVC应用程序,动态创建单选列表(RadioButtonList)
- CheckBoxList和RadioButtonList的使用(后台取值和赋值)
- 关于DropDownList、RadioButtonList和CheckBoxList绑定