vishnu vardhan

vishnu vardhan

  • NA
  • 112
  • 28.8k

drop down list is not taking selected value

Apr 5 2014 3:47 AM
Hello All,
 
           I am working on some project there i have 2 drop down lists and one Textbox in Update panel1. here i am binding the Names of PG from database to dropdownlist1(DDPGNames) and binding the PG rooms to dropdownlist2(DDRoomNumber) based first dropdownlist (it's like Country and state thing) now if i select any Room number in 2nd Dropdownlist the room rent has to dispaly automatically in textbox. for this i am writing this code on DDRoomNumber SelectIndexChanged Event. but my problem is DDRoomNumber is not taking selected room Number (It is taking Only First Value) if i select any other room in dropdown list it's going first one only.

see here my code:

    protected void DDRoomNumber_SelectedIndexChanged(object sender, EventArgs e)
        {
            txtRent.Enabled = true;
            MySqlConnection Con = new MySqlConnection(MyConString);
            MySqlCommand Cmd = Con.CreateCommand();
            string S = "SELECT*FROM pg_room_list WHERE Room_Num ='" + DDRoomNumber.SelectedItem.Text + "' AND Room_PG_ID ='" + DDPGNames.SelectedValue + "';";
            Cmd = new MySqlCommand(S, Con);
            MySqlDataReader Dr;
            Con.Open();
            Dr = Cmd.ExecuteReader();
            while (Dr.Read())
            {
                string SRoom_Rent = Dr.GetString("Room_Rent");
                txtRent.Text = SRoom_Rent;
            }
            Con.Close();    
        }          

Pls give me some solution.

Thanks 

Answers (32)