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

vishnu vardhanPosted Apr 8, 2014, 4:08 PM
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.
Dorababu MekaPosted Apr 8, 2014, 2:37 PM
vishnu vardhanPosted Apr 8, 2014, 2:35 PM
Thanks Again
Dorababu MekaPosted Apr 8, 2014, 2:13 PM
vishnu vardhanPosted Apr 8, 2014, 6:28 AM
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
vishnu vardhanPosted Apr 8, 2014, 2:11 AM
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 MekaPosted Apr 8, 2014, 1:17 AM
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 vardhanPosted Apr 7, 2014, 2:41 PM
thanks
Dorababu MekaPosted Apr 7, 2014, 12:48 PM
vishnu vardhanPosted Apr 7, 2014, 12:39 PM
pls open it.
thanks
Dorababu MekaPosted Apr 7, 2014, 12:12 PM
vishnu vardhanPosted Apr 7, 2014, 11:34 AM
Pls give me some solution
thanks
vishnu vardhanPosted Apr 7, 2014, 10:46 AM
I have attached the code see and tell me any wrong is there
Thanks
Dorababu MekaPosted Apr 7, 2014, 9:42 AM
vishnu vardhanPosted Apr 7, 2014, 8:51 AM
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
vishnu vardhanPosted Apr 7, 2014, 2:27 AM
Here my aspx code
Here my .aspx.cs code
Thanks
Srikanth ReddyPosted Apr 7, 2014, 2:15 AM
vishnu vardhanPosted Apr 7, 2014, 2:12 AM
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 ReddyPosted Apr 7, 2014, 2:04 AM
vishnu vardhanPosted Apr 7, 2014, 1:17 AM
i don't know how to debug the programs in VS 2012 can u just tell me how to do it?
thanks
vishnu vardhanPosted Apr 7, 2014, 1:14 AM
vishnu vardhanPosted Apr 7, 2014, 1:12 AM
Check
Thanks
vishnu vardhanPosted Apr 7, 2014, 1:11 AM
Jignesh TrivediPosted Apr 7, 2014, 12:58 AM
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?
Srikanth ReddyPosted Apr 7, 2014, 12:58 AM
The Code of munesh sharma is right and put "auto post back" of dropdown list is "true"...........
Lakshmanan Sethu SankaranarayanPosted Apr 7, 2014, 12:44 AM
Munesh SharmaPosted Apr 7, 2014, 12:27 AM
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);
}
}
}vishnu vardhanPosted Apr 6, 2014, 1:24 PM
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
vishnu vardhanPosted Apr 5, 2014, 5:15 AM
Munesh SharmaPosted Apr 5, 2014, 4:50 AM
vishnu vardhanPosted Apr 5, 2014, 4:44 AM
Munesh SharmaPosted Apr 5, 2014, 4:22 AM
"+DDRoomNumber.Selectedvalue+"