首页 > 代码库 > 2017-5-7 三级联动
2017-5-7 三级联动
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using 三级联动.App_code; namespace 三级联动 { public partial class Form1 : Form { public Form1() { InitializeComponent(); bind("0001",comboBox1); bind(comboBox1.SelectedValue.ToString(),comboBox2); bind(comboBox2.SelectedValue.ToString(),comboBox3); } public void bind(string pcode, ComboBox cb) { List<chinastate> clist = new chinastatedata().select(pcode); cb.DataSource = clist; cb.DisplayMember = "AreaName"; cb.ValueMember = "AreaCode"; } private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { bind(comboBox1.SelectedValue.ToString(), comboBox2); if (comboBox2.SelectedValue!=null) { bind(comboBox2.SelectedValue.ToString(), comboBox3); } } private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) { bind(comboBox2.SelectedValue.ToString(), comboBox3); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 三级联动.App_code { public class chinastate { private string _AreaCode; public string AreaCode { get { return _AreaCode; } set { _AreaCode = value; } } private string _AreaName; public string AreaName { get { return _AreaName; } set { _AreaName = value; } } private string _ParentAreaCode; public string ParentAreaCode { get { return _ParentAreaCode; } set { _ParentAreaCode = value; } } } }
using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Linq; using System.Text; using System.Threading.Tasks; namespace 三级联动.App_code { public class chinastatedata { SqlConnection conn=null; SqlCommand cmd=null; public chinastatedata() { conn = new SqlConnection("server=.;database=data0216;user=sa;pwd=123"); cmd = conn.CreateCommand(); } public List<chinastate> select(string pcode) { List<chinastate> clist = new List<chinastate>(); cmd.CommandText = "select * from ChinaStates where ParentAreaCode=@a"; cmd.Parameters.Clear(); cmd.Parameters.AddWithValue("@a",pcode); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(); while(dr.Read()) { chinastate c = new chinastate(); c.AreaCode = dr[0].ToString(); c.AreaName = dr[1].ToString(); c.ParentAreaCode = dr[2].ToString(); clist.Add(c); } conn.Close(); return clist; } } }
2017-5-7 三级联动
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。