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

Popular posts from this blog

How to understand 2 main() functions after using uftrace to profile the C++ program? -

c# - Update a combobox from a presenter (MVP) -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -