private void drpProvinceBind()
    {
        con = new SqlConnection(connstr);
        con.Open();
        com = new SqlCommand("select * from Province", con);
        read = com.ExecuteReader();
        DropDownList3.DataSource = read;
        DropDownList3.DataValueField = "ID";
        DropDownList3.DataTextField = "Province";
        DropDownList3.DataBind();
        DropDownList3.Items.Insert(0, "--请选择省份--");
        DropDownList4.Items.Insert(0, "--请选择城市--");
        con.Close();
    }
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
    {
        con = new SqlConnection(connstr);
        con.Open();
        com = new SqlCommand("select * from city where provid='" + DropDownList3.SelectedItem.Value + "'", con);
        read = com.ExecuteReader();
        DropDownList4.DataSource = read;
        DropDownList4.DataTextField = "city";
        DropDownList4.DataValueField = "Provid";
        DropDownList4.DataBind();
        con.Close();
    }
我现在要取出值,可取出的是对应的ID,我要怎么做?谢谢

解决方案 »

  1.   

    DropDownList3.SelectedItem.Value //取值
    DropDownList3.SelectedItem.Text //取文本
      

  2.   

    DropDownList3.SelectedValue //取值 
    DropDownList3.SelectedItem.Text //取文本
      

  3.   


    楼上正确
    com = new SqlCommand("select * from city where provid='" + DropDownList3.SelectedItem.Value + "'", con); 
    关联的是provid啊,怎么要值了况且楼主用sqldatareader,怎么没关闭那
    只关闭connection
      

  4.   

    DropDownList3.DataValueField = "ID"; 
    这句有问题
    很明显你绑的是ID当然取出的是对应的ID改正方法:DropDownList3.DataValueField = "Province"; DropDownList3.DataTextField = "Province"; 
      

  5.   

    DropDownList3.SelectedItem.Value //取值 
    DropDownList3.SelectedItem.Text //取文本
      

  6.   

    用微软的ajax吧,刷新联动没意思