我正在尝试将下拉列表选择的值保存在 glbal 变量中。我在下拉列表中有很多国家/地区,当我选择其中一个并按下按钮时:
protected void Button1_Click(object sender, EventArgs e)
{
Button2.Enabled = true;
Button2.Visible = true;
DropDownList1.Visible = true;
DropDownList9.Items.Clear();
if (!Class1.Search_Continent.Equals("-"))
{
SqlConnection conn1 = new SqlConnection(@"Data Source=AK-PC\MSSQLSERVER1;Initial Catalog=DB;Integrated Security=True");
conn1.Open();
SqlCommand cmd1 = new SqlCommand("Select Country_name FROM Country WHERE Continent_name='" + DropDownList1.SelectedValue + "'", conn1);
SqlDataReader dr1;
dr1 = cmd1.ExecuteReader();
while (dr1.Read())
{ DropDownList9.Items.Add(dr1["Country_name"].ToString() + "\n"); }
dr1.Close();
conn1.Close();
}
protected void Button2_Click(object sender, EventArgs e)
{
// Redirect to Country page
Class1.CountryName = DropDownList9.SelectedValue.ToString();
Response.Redirect("Country.aspx", true);
}
它不采用选定的值!它总是取下拉列表的第一个值!请帮我 !