2017-5-7 三级联动

Posted Zoe

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 三级联动的主要内容,如果未能解决你的问题,请参考以下文章

2017-5-7 time控件 三级联动(省,市,区)

2017-5-7 time控件 三级联动(省,市,区)

三级联动怎么回显 javaweb

c# 求WPF省市区三级联动代码,是从xml中得到省市区数据后添加到三个下拉列表。

ios收货地址三级联动选择

ajax省市区三级联动