Click here to Skip to main content
15,063,944 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have form in asp.net mvc that retrieves records from database.this form have dropdowns. in Edit action of controller it is must to have selected the already inserted items. suppose if i am taking the User information for edit, then its City,State and country must be selected as they inserted before.Can any one tell me how to set values from database as selected in drop down list when page loads???
Posted
Updated 3-May-11 19:34pm
v2

1 solution

If I am understanding correct then you can use any one of them.

if (DropDownList1.Items.FindByText("ITEMTEXT") != null)
      DropDownList1.Items.FindByText("ITEMTEXT").Selected = true;

OR
if (DropDownList1.Items.FindByValue("ITEMTEXT") != null)
      DropDownList1.Items.FindByValue("ITEMTEXT").Selected = true;
   

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