• 省市联动 DropDownList AutoPostBack


    protected void Page_Load(object sender, EventArgs e)
        {
            SQLHelper sqH;
            if (!Page.IsPostBack)
            {
                sqH = new SQLHelper();
                string strSelPro = "SELECT [proName] FROM [db_city].[dbo].[tb_province] ";
                DataTable dt = sqH.ExecuteQuery(strSelPro,CommandType.Text);
                if (dt.Rows.Count > 0)
                {
                    DropDownList1.DataSource = dt;
                    DropDownList1.DataValueField = dt.Columns[0].ColumnName;
                    DropDownList1.DataTextField = dt.Columns[0].ColumnName;
                    DropDownList1.DataBind();
                }


                //try
                
    //{
                
    //    using (SqlConnection sqlCon = new SqlConnection("server=.;database=db_city;uid=sa;pwd="))
                
    //    {
                
    //        sqlCon.Open();
                
    //        string strSelPro = "SELECT [proName] FROM [db_city].[dbo].[tb_province] ";
                
    //        SqlCommand sqlCom = new SqlCommand(strSelPro, sqlCon);
                
    //        SqlDataReader sdr = sqlCom.ExecuteReader();
                
    //        while (sdr.Read())
                
    //        {
                
    //            DropDownList1.Items.Add(sdr[0].ToString());
                
    //        }
                
    //        sdr.Close();

                
    //        string strSelCity = "SELECT [proName],b.[cityName],a.[proID],b.[proID] FROM [db_city].[dbo].[tb_province] as a,[db_city].[dbo].[tb_city] as b  ";
                
    //        strSelCity += "where a.[proID]=b.[proID] and [proName]='" + DropDownList1.SelectedItem.Text + "'";
                
    //        sqlCom = new SqlCommand(strSelCity, sqlCon);
                
    //        sdr = sqlCom.ExecuteReader();
                
    //        while (sdr.Read())
                
    //        {
                
    //            DropDownList2.Items.Add(sdr[1].ToString());
                
    //        }
                
    //        sdr.Close();
                
    //    }
                
    //}
                
    //catch (Exception ex)
                
    //{
                
    //    throw ex;
                
    //}
                
    //finally
                
    //{
                
    //}
                
            }
            
        }
        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            //DropDownList2.Items.Clear();
            
    //try
            
    //{
            
    //    using (SqlConnection sqlCon = new SqlConnection("server=.;database=db_city;uid=sa;pwd="))
            
    //    {
            
    //        sqlCon.Open();
            
    //        string strSelCity = "SELECT [proName],b.[cityName],a.[proID],b.[proID] FROM [db_city].[dbo].[tb_province] as a,[db_city].[dbo].[tb_city] as b  ";
            
    //        strSelCity += "where a.[proID]=b.[proID] and [proName]='" + DropDownList1.SelectedItem.Text + "'";
            
    //        SqlCommand sqlCom = new SqlCommand(strSelCity, sqlCon);
            
    //        SqlDataReader sdr = sqlCom.ExecuteReader();
            
    //        while (sdr.Read())
            
    //        {
            
    //            DropDownList2.Items.Add(sdr[1].ToString());
            
    //        }
            
    //        sdr.Close();
            
    //    }
            
    //}
            
    //catch (Exception ex)
            
    //{
            
    //    throw ex;
            
    //}
            
    //finally
            
    //{
            
    //}
        }
  • 相关阅读:
    能大大提升工作效率和时间效率的9个重要习惯
    hibernate的校验
    8. semahpore原理
    chklist
    android textview 自动换行 整齐排版
    fiddler接口测试,js代码修改日志展示(埋点用)
    Python模块之 tqdm进度条
    Python抓取网页到本地
    Python模块之 clint 进度条
    python windows下pip安装错误whl文件安装错误
  • 原文地址:https://www.cnblogs.com/hishanghai/p/2548699.html
Copyright © 2020-2023  润新知