數據綁定

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";

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章