c# - retrieve data from to textbox according to dropdownlist selection -
here code, when replace dropdownlist.selectedvalue real id works well, need change when select id dropdownlist :
protected void page_load(object sender, eventargs e) { sqlcommand com = new sqlcommand("select * userstable username='" + dropdownlistusers.selectedvalue + "'", conn); try { conn.open(); using (sqldatareader red = com.executereader()) { while (red.read()) { textboxpass.text = (red["password"].tostring()); textboxfname.text = (red["fname"].tostring()); textboxlname.text = (red["lname"].tostring()); textboxaddress.text = (red["address"].tostring()); textboxphone.text = (red["phoneno"].tostring()); textboxemail.text = (red["email"].tostring()); textboxpass.text = (red["password"].tostring()); } } } { conn.close(); } }
just add .tostring();
dropdownlistusers.selectedvalue.tostring(); and sure @hung said if want put in page load make sure put
dropdownlistusers.selectedindex = 0; or default value before code above
Comments
Post a Comment