数据绑定

来源:互联网 发布:苏联狗头实验 知乎 编辑:程序博客网 时间:2024/06/16 17:40

VS环境下的数据绑定小测试:

protected void Page_Load(object sender, EventArgs e)
    {
        string str = "data source=.;initial catalog=MY_lianxi;integrated security=true";
        DataSet ds = new DataSet();
        using (SqlConnection sqlCnn = new SqlConnection(str))
        {
            SqlCommand sqlCmm = sqlCnn.CreateCommand();
            sqlCmm.CommandText = "select ID,shengfen from shengfen";
            SqlDataAdapter da = new SqlDataAdapter(sqlCmm);
            da.Fill(ds);
        }
        this.CheckBoxList1.DataSource = ds.Tables[0];
        this.CheckBoxList1.DataTextField = "shengfen";
        //this.CheckBoxList1.DataValueField = "ID";

        this.RadioButtonList1.DataSource = ds;
        this.RadioButtonList1.DataTextField = "shengfen";
        //this.RadioButtonList1.DataValueField = "ID";

 

原创粉丝点击