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