<%@ Page Language="C#" AutoEventWireup="true" CodeFile="listbox.aspx.cs" Inherits="test_listbox" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>无标题页</title>
</head>
<body>
    <form ;
            this.DropDownList1.DataBind();
            sdr.Close();
            //con.Close();

            SqlCommand cmdCity =new SqlCommand("select * from city where proID=" + this.DropDownList1.SelectedValue.ToString(),con);
            sdr = cmdCity.ExecuteReader();
            this.DropDownList2.DataSource = sdr;
            this.DropDownList2.DataValueField = "cityID";
            this.DropDownList2.DataTextField = "cityName";
            this.DropDownList2.DataBind();
            sdr.Close();

            con.Close();
        }

    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        this.ListBox1.Items.Add(this.TextBox1.Text);
    }
    protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
        Label1.Text = "你已经选择了:" + this.ListBox1.SelectedItem.Text;
    }
    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        SqlConnection con = DB2.createConnection();
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from city where proID=" + this.DropDownList1.SelectedValue.ToString(), con);
        SqlDataReader sdr = cmd.ExecuteReader();
        this.DropDownList2.DataSource = sdr;
        this.DropDownList2.DataValueField = "cityID";
        this.DropDownList2.DataTextField = "cityName";
        this.DropDownList2.DataBind();
        sdr.Close();

        con.Close();
    }
}

下面一节课是: DropDownList 与 ListBox 的联动!

相关文章:

  • 2021-09-13
  • 2021-11-27
  • 2021-07-23
  • 2021-07-14
  • 2022-12-23
  • 2021-11-05
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-09
  • 2021-05-31
  • 2022-12-23
  • 2021-05-17
相关资源
相似解决方案