- 爱易网页
-
ASP.NET教程
- DropDownlist联动,为什么第二个的值老是不对。该怎么解决
日期:2014-05-19 浏览次数:20516 次
DropDownlist联动,为什么第二个的值老是不对。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.drop1();
this.drop2();
}
Label1.Text = this.DropDownList1.SelectedValue;
Label2.Text = this.DropDownList2.SelectedValue;
}
public void drop1()
{
con.Open();
string sql = "select * from col ";
DataTable dt = new DataTable();
SqlDataAdapter da=new SqlDataAdapter(sql,con.Conn);
da.Fill(dt);
DropDownList1.DataSource = dt;
DropDownList1.DataTextField = "cname ";
DropDownList1.DataValueField = "id ";
DropDownList1.SelectedValue = this.DropDownList1.SelectedValue;
DropDownList1.DataBind();
con.Close();
}
public void drop2()
{
con.Open();
string sql = "select * from cl where ccode= ' "+DropDownList1.SelectedValue+ " ' ";
DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql, con.Conn);
da.Fill(dt);
DropDownList2.DataSource = dt;
DropDownList2.DataTextField = "name ";
DropDownList2.DataValueField = "id ";
DropDownList2.DataBind();
con.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)