实现代码基本如下,但就是没效果,我选择第一个框后,第二个框并没有变化
.NET代码: 学院:
<asp:DropDownList ID="college" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
Width="221px" Enabled="False">
</asp:DropDownList>CS代码: protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);
con.Open();
string college1 = this.college.Text;
SqlDataAdapter sda = new SqlDataAdapter(" select speciality from ts_unit_collgeSpeciality where collegeName ='" + college1 + "'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "ts_unit_collgeSpeciality");
//DataRowView rowview = ds.Tables["ts_xs_professionalCourses"].DefaultView[0];
this.speciality.DataSource = ds.Tables["ts_unit_collgeSpeciality"]; this.speciality.DataTextField = "speciality";
this.speciality.DataBind();
con.Close();
}
.NET代码: 学院:
<asp:DropDownList ID="college" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged"
Width="221px" Enabled="False">
</asp:DropDownList>CS代码: protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["strcon"]);
con.Open();
string college1 = this.college.Text;
SqlDataAdapter sda = new SqlDataAdapter(" select speciality from ts_unit_collgeSpeciality where collegeName ='" + college1 + "'", con);
DataSet ds = new DataSet();
sda.Fill(ds, "ts_unit_collgeSpeciality");
//DataRowView rowview = ds.Tables["ts_xs_professionalCourses"].DefaultView[0];
this.speciality.DataSource = ds.Tables["ts_unit_collgeSpeciality"]; this.speciality.DataTextField = "speciality";
this.speciality.DataBind();
con.Close();
}
最好用先指定Value值,然后用SelectedValue 获得