在C#中怎么把treeview和数据库中的三张表递归绑定(比如说中国的省、市、县)
1个回答
展开全部
//先初始化省
SqlConnection con = new SqlConnection(DBHelper.sql);
con.Open();
SqlCommand cmdPro = new SqlCommand("……", con);
SqlDataReader drPro = cmdPro.ExecuteReader();
this.ddlProvince.DataSource = drPro;
this.ddlProvince.DataTextField = "name";//显示值
this.ddlProvince.DataValueField = "code"; //显示主键
this.ddlProvince.DataBind();
drPro.Close();
this.ddlProvince.Items.Insert(0, new ListItem("-请选择省-", ""));
//初始化市
SqlCommand cmdCity = new SqlCommand("……,con);
SqlDataReader drCity = cmdCity.ExecuteReader();
this.ddlCity.DataSource = drCity;
this.ddlCity.DataTextField = "name";
this.ddlCity.DataValueField = "ProvinceID";
this.ddlCity.DataBind();
drCity.Close();
this.ddlCity.Items.Insert(0, new ListItem("-请选择市-", ""));
跟dropdownlist三级联动是一样的,给你参考一下,希望有帮助
SqlConnection con = new SqlConnection(DBHelper.sql);
con.Open();
SqlCommand cmdPro = new SqlCommand("……", con);
SqlDataReader drPro = cmdPro.ExecuteReader();
this.ddlProvince.DataSource = drPro;
this.ddlProvince.DataTextField = "name";//显示值
this.ddlProvince.DataValueField = "code"; //显示主键
this.ddlProvince.DataBind();
drPro.Close();
this.ddlProvince.Items.Insert(0, new ListItem("-请选择省-", ""));
//初始化市
SqlCommand cmdCity = new SqlCommand("……,con);
SqlDataReader drCity = cmdCity.ExecuteReader();
this.ddlCity.DataSource = drCity;
this.ddlCity.DataTextField = "name";
this.ddlCity.DataValueField = "ProvinceID";
this.ddlCity.DataBind();
drCity.Close();
this.ddlCity.Items.Insert(0, new ListItem("-请选择市-", ""));
跟dropdownlist三级联动是一样的,给你参考一下,希望有帮助
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询