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
Pls give me some solution.
Thanks


Munesh SharmaRank #174 · 13.9K reputationPosted Apr 5, 2014, 12:22 AM EDT
"+DDRoomNumber.Selectedvalue+"
vishnu vardhan107 reputationPosted Apr 5, 2014, 12:44 AM EDT
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 5, 2014, 12:50 AM EDT
vishnu vardhan107 reputationPosted Apr 5, 2014, 1:15 AM EDT
vishnu vardhan107 reputationPosted Apr 6, 2014, 9:24 AM EDT
see here i am using those drop down lists in Update Panel so is something i have to do ? like triggers?
pls can any one know the solution?
Thanks
Munesh SharmaRank #174 · 13.9K reputationPosted Apr 6, 2014, 8:27 PM EDT
you do like this
Click on drop down list in write this code
{
string str = "server = MUNESH\\SQL2008R2;Database=datastore;UID=sa;Password=123;";
SqlConnection con = new SqlConnection(str);
string query = "select * from tablename where name = '"+dropdownlist.text+"' ";
SqlCommand cmd = new SqlCommand( query,con);
sqldatareader dbr;
try
{
con.open();
dbr = cmd.executereader();
while(dbr.read())
{
string sID = (string) dbr["ID"].tostring;
string sname = (string) dbr["name"] // name is string value
string sage = (string) dbr["age"].tostring;
textbox1.text = sid;
textbox2.text = sname;
textbox3.text = sage;
}
catch(execption es)
{
messagebox.show(es.message);
}
}
}Lakshmanan Sethu SankaranarayanRank #124 · 17.7K reputationPosted Apr 6, 2014, 8:44 PM EDT
Srikanth Reddy142 reputationPosted Apr 6, 2014, 8:58 PM EDT
The Code of munesh sharma is right and put "auto post back" of dropdown list is "true"...........
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 6, 2014, 8:58 PM EDT
hi,
It might be value of drop down may reset on page load....
because before this event of drop down called page load event is fired...
can you please share your page load code?
vishnu vardhan107 reputationPosted Apr 6, 2014, 9:11 PM EDT
vishnu vardhan107 reputationPosted Apr 6, 2014, 9:12 PM EDT
Check
Thanks
vishnu vardhan107 reputationPosted Apr 6, 2014, 9:14 PM EDT
vishnu vardhan107 reputationPosted Apr 6, 2014, 9:17 PM EDT
i don't know how to debug the programs in VS 2012 can u just tell me how to do it?
thanks
Srikanth Reddy142 reputationPosted Apr 6, 2014, 10:04 PM EDT
vishnu vardhan107 reputationPosted Apr 6, 2014, 10:12 PM EDT
my problem is with second drop down list it's not taking the selected value. if i select any value then it's automatically going to the 1st value...
Thanks
Srikanth Reddy142 reputationPosted Apr 6, 2014, 10:15 PM EDT
vishnu vardhan107 reputationPosted Apr 6, 2014, 10:27 PM EDT
Here my aspx code
Here my .aspx.cs code
Thanks
vishnu vardhan107 reputationPosted Apr 7, 2014, 4:51 AM EDT
did anyone find anything ?? pls i need this. still i didn't get anything..
pls Can anyone give me the solution i am stuck on this from last one day...
thanks
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 7, 2014, 5:42 AM EDT
vishnu vardhan107 reputationPosted Apr 7, 2014, 6:46 AM EDT
I have attached the code see and tell me any wrong is there
Thanks
vishnu vardhan107 reputationPosted Apr 7, 2014, 7:34 AM EDT
Pls give me some solution
thanks
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 7, 2014, 8:12 AM EDT
vishnu vardhan107 reputationPosted Apr 7, 2014, 8:39 AM EDT
pls open it.
thanks
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 7, 2014, 8:48 AM EDT
vishnu vardhan107 reputationPosted Apr 7, 2014, 10:41 AM EDT
thanks
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 7, 2014, 9:17 PM EDT
string S = "SELECT Room_Num,Room_PG_ID FROM pg_room_list WHERE Room_PG_ID='" + DDPGNames.SelectedValue + "';";
is Room_PG_ID foreignkey or primary key, if foreign key what is your primary key in this table
vishnu vardhan107 reputationPosted Apr 7, 2014, 10:11 PM EDT
Ya i am facing problem on that DDRoomNumber_SelectIndexChanged event
When ever i will select any room number the value is going to first value only.
it's not taking selected value.
Thanks
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 8, 2014, 10:13 AM EDT
vishnu vardhan107 reputationPosted Apr 8, 2014, 10:35 AM EDT
Thanks Again
Dorababu MekaRank #457 · 5.5K reputationPosted Apr 8, 2014, 10:37 AM EDT
vishnu vardhan107 reputationPosted Apr 8, 2014, 12:08 PM EDT
In Binding the RoomNumbers I wrote the code like this
DDRoomNumber.DataValueField = "Room_Num"; // Correct
Here my mistake is i am taking the DataValueField as Room_PG_ID this was wrong because i need to give the same value of Room_Num so i changed it into Room_Num. Now it's Working.
It's Just Commonsense previously i was not looking at this Bind_RoomNumbers. Just i was checking on SelectedIndexChenged Event only. Just before i sat down and observed all the code once so i got my silly mistake.
Thanks any way For your Replies and precious Time of you Guys.
vishnu vardhan107 reputationPosted Apr 8, 2014, 2:28 AM EDT
Did You find anything sir?? pls i need it very badly. i don't know what i have done wrong in this because my code is correct only and the query also working but the dropdown list is not selecting selected value.
Thanks