webform 下拉列表联动
ublic partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { DropDown(); } } protected void Button1_Click(object sender, EventArgs e) { string userName = TextBox1.Text; string userPass = TextBox2.Text; //HttpCookie cookie = Request.Cookies["userName"]; ////string value = cookie.Value; //if (cookie.Value == user) //{ // HttpCookie cookie2 = Request.Cookies["userPass"]; // TextBox2.Text = cookie2.Value; //} bool user = new UserdBF().Select(userName, userPass); if (user) { if (CheckBox1.Checked) { HttpCookie cookie1 = new HttpCookie("userName", userName); cookie1.Expires = DateTime.Now.AddHours(2); Response.SetCookie(cookie1); HttpCookie cookie2 = new HttpCookie("userPass", userPass); cookie2.Expires = DateTime.Now.AddHours(2); Response.SetCookie(cookie1); } Response.Write("<script>alert('登录成功');</script>"); } else { Response.Write("<script>alert('用户名或密码错误');</script>"); } } protected void Button2_Click(object sender, EventArgs e) { Response.Redirect("Default2.aspx"); } public void DropDown() { List<AreaFull> list = new AreaBF().Select(0); DropDownList1.DataSource = list; DropDownList1.DataTextField = "AreaName"; DropDownList1.DataValueField = "AreaId"; DropDownList1.DataBind(); int a = Convert.ToInt32(DropDownList1.SelectedItem.Value); List<AreaFull> listS = new AreaBF().Select(a); DropDownList2.DataSource = listS; DropDownList2.DataTextField = "AreaName"; DropDownList2.DataValueField = "AreaId"; DropDownList2.DataBind(); int b = Convert.ToInt32(DropDownList2.SelectedItem.Value); List<AreaFull> listQ = new AreaBF().Select(b); DropDownList3.DataSource = listQ; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaId"; DropDownList3.DataBind(); TextBox3.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text + DropDownList3.SelectedItem.Text; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { int a = Convert.ToInt32(DropDownList1.SelectedItem.Value); List<AreaFull> listS = new AreaBF().Select(a); DropDownList2.DataSource = listS; DropDownList2.DataTextField = "AreaName"; DropDownList2.DataValueField = "AreaId"; DropDownList2.DataBind(); int b = Convert.ToInt32(DropDownList2.SelectedItem.Value); List<AreaFull> listQ = new AreaBF().Select(b); DropDownList3.DataSource = listQ; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaId"; DropDownList3.DataBind(); TextBox3.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text + DropDownList3.SelectedItem.Text; } protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { int b = Convert.ToInt32(DropDownList2.SelectedItem.Value); List<AreaFull> listQ = new AreaBF().Select(b); DropDownList3.DataSource = listQ; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaId"; DropDownList3.DataBind(); TextBox3.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text + DropDownList3.SelectedItem.Text; } protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e) { TextBox3.Text = DropDownList1.SelectedItem.Text + DropDownList2.SelectedItem.Text + DropDownList3.SelectedItem.Text; } }