文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>asp.net checkboxlist绑定数据读取出来

asp.net checkboxlist绑定数据读取出来

时间:2010-08-16  来源:夏楚枫

1.把数据绑定到CheckBoxList中

protected void Page_Load(object sender, EventArgs e)
{
    if (!Page.IsPostBack)
    {
        SqlConnection con = GetDBCon.GetCon();
        con.Open();
        SqlDataAdapter sda = new SqlDataAdapter("select * from admin", con);
        DataSet ds = new DataSet();
        sda.Fill(ds,"admin");
        this.CheckBoxList1.DataSource = ds.Tables[0];
        this.CheckBoxList1.DataTextField = "username";//绑定的字段名
        this.CheckBoxList1.DataValueField = "userid";//绑定的值
        this.CheckBoxList1.DataBind();       
    }
} 


2.循环读取出来

protected void CheckBoxList1_SelectedIndexChanged(object sender, EventArgs e)
{
    this.Lab2.Text = "";
    for (int i = 0; i < CheckBoxList1.Items.Count; i++)
    {
        if (this.CheckBoxList1.Items[i].Selected)
        {
            this.Lab2.Text = this.Lab2.Text+CheckBoxList1.Items[i].Text+".";
        }
    }
}

相关阅读 更多 +
排行榜 更多 +
宝宝切水果安卓版

宝宝切水果安卓版

休闲益智 下载
儿童脑筋急转弯

儿童脑筋急转弯

休闲益智 下载
袭击现场2

袭击现场2

飞行射击 下载