本帖最后由 x1aoli 于 2011-11-03 22:34:49 编辑

解决方案 »

  1.   

    第一个省市下拉框加事件 DropDownList1_SelectedIndexChanged
    触发事件后得到第一个下拉的值,在查询到城市的数据 
    绑定第二个下拉框
      

  2.   


    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"></asp:DropDownList><asp:DropDownList ID="DropDownList2" runat="server"></asp:DropDownList>public void Page_Load(object sender,EventArgs e)
    {
        if(!IsPostBack)
        {
              this.DropDownList1.DataSource = getDataSet("Province");
              this.DropDownList1.DataTextField= "ProvinceName";
              this.DropDownList1.DataValueField= "ID";
              this.DropDownList1.DataBind();
              this.DropDownList1.Items.Insert(0,"--请选择--");
        }
        
    }public void DropDownList1_SelectedIndexChanged(object sender,EventArgs e)
    {
            if(this.DropDownList1.SelectedIndex!=0)
            {
                  this.DropDownList2.DataSource = getDataSet("City",int.Parse(this.DropDownList1.SelectedItem.Value));
                  this.DropDownList2.DataTextField= "CityName";
                  this.DropDownList2.DataValueField= "ID";
                  this.DropDownList2.DataBind();
            }
    } //获取数据集  ,根据你实际的数据库连接字符串进行相应修改
    public DataSet getDataSet(string tableName)  
    {  
         DataSet ds = new DataSet();  
         using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN"))  
          {  
                con.Open();  
                string strSQL = "select * from "+tableName;  
                using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con))  
                {  
                     sda.Fill(ds);  
                }  
           }  
           return ds;  
     }  public DataSet getDataSet(string tableName,int args)  
    {  
         DataSet ds = new DataSet();  
         using (SqlConnection con = new SqlConnection("Data Source=localhost;uid=sa;pwd=sa;Database=CSDN"))  
          {  
                con.Open();  
                string strSQL = "select * from "+tableName+" where PID="+args;  
                using (SqlDataAdapter sda = new SqlDataAdapter(strSQL, con))  
                {  
                     sda.Fill(ds);  
                }  
           }  
           return ds;  
     }  
      

  3.   

    like this:
    http://www.cnblogs.com/insus/archive/2011/07/04/2097059.html