Click here to Skip to main content
15,922,650 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have country in table and i want to bind country in dropdown but by default selected country is which is that user country in table...example suppose when i register that that time i was selected my country is india and when i login then in that dropdown all country fetch from database but by default selected country is 'india'...so how can i do????
plz help me.
Posted
Comments
Sachin Gargava 20-Dec-12 0:21am    
what actually you want write little more clear.

When your question is both a paragraph and one sentence, the odds of you making sense, are low.

I think you're saying you want your drop down list to preselect the current value ? That's easy. The drop list has a selected value property. You can set it in your ASPX, or in your code behind.
 
Share this answer
 
1. Bind your contry dropdown list with DataTextField = "CountryName" and DataValueField = "CountryId"
2. Fetch the user data
3. Once u fetch the data of selected user then write following line in your code behind file
ddlContry.Items.FindbyValue(usercontryid).Selected = true;
 
Share this answer
 
If I am not wrong, You want the selected country of the User (What ever he had selected while registering himself).
What you have to do is very simple. Fetch data from your table and assign the value of your country dropdown with the value coming from database.

for ex

C#
//write your query here
//after that Fetch data from database and fill dataset or datatable
//It's must to fill your Country Dropdown before assigning the selected value

ddlCountry.SelectedValue=dt.rows[0]["CountryID"].ToString();


Thanks
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900