我想dropdownlist
根据从 other 中选择的房间类型填充房间号dropdownlist
。但是在从dropdown
其他值中选择房间类型时,dropdown
每次都会重复。这是sql表和程序。
Room num, Room type, Cost, Status
A1 AC 223 Av
B2 Non Ac 180 Av
public partial class customer_reservation : System.Web.UI.Page
{
string connectionString = WebConfigurationManager.ConnectionStrings["newdb"].ConnectionString;
protected void Page_Load(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string rval = DropDownList1.SelectedValue.ToString();
SqlConnection con = new SqlConnection(connectionString);
con.Open();
string qry = "select Roomnum from room where rtype=@rval and rstatus like 'AV'";
SqlCommand cmd = new SqlCommand(qry,con);
cmd.Parameters.AddWithValue("@rval",rval);
SqlDataReader rd1 = cmd.ExecuteReader();
if (rd1.HasRows)
{
while (rd1.Read())
{
DropDownList2.Items.Add(rd1[0].ToString());
}
}
con.Close();
}
}