Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

selecting values in drop down lists 1

Status
Not open for further replies.

thehms

Programmer
Jul 3, 2003
58
0
0
AE
hi all...

i am retrieving a users profile from a database, and among the data there is a country field. the country is originally chose by a drop down list. when the page loads the data it selects the first data item in the list. how can i make it to choose the country that was originally selected by the user...?

the data thats stored in the database is the id of the country...

and also i have the same problem with radio buttons. i want to be able to select the one that has been selected in the databse....

thanks
The HMS
 
1. Retrieve the database values. Let's say that CountryID is the stored value. Assign it to a variable so we have (somewhere):
Code:
{
string CountryID = reader["CountryID"].ToString();
}
Then when you load your DropDownList from the db:
Code:
{
ddlCountry.DataSource=YourReaderOrDataSet;
ddlCountry.DataBind();
ddlCountry.Items.FindByValue(CountryID).Selected=true;
}
Check Boxes and Radio Buttons can be handled like this:
Code:
if(reader["myDatabaseValue"] != DBNull.Value)
{
   myDataBaseValue = Convert.ToBoolean(reader["myDataBaseValue"]);
}
radMyRadio.Checked = myDataBaseValue;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top