Click here to Skip to main content
15,885,032 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i have a dropdown list ,the values are coming from database ,how to select the dropdownvalue from database

suppose
in dropdown 1,2,3,4,5 will come
by default 3 should be selected and u can not select that one
3 will be the selected value by the user previous,this is stored in the database and retrivig it in dropdown
Posted
Updated 15-Dec-15 21:17pm
v2
Comments
Sinisa Hajnal 16-Dec-15 4:19am    
What have you tried?

Normally you would put selected id in helper call or if you're constructing HTML directly you'd add selected="true" property to the item in question.
Member 11970398 16-Dec-15 5:45am    
can u help me with this
Sinisa Hajnal 16-Dec-15 8:08am    
Not without code. Google it, you'll find basic examples. If you already have the code that doesn't work, you have to post it here, we don't see your screen or see your system.
[no name] 16-Dec-15 4:27am    
Can you provide your relevant code how are you loading values to your dropdownlist?

DataTable dt = ds_Job_Open.Tables[0];

if (dt.Rows.Count > 0)
{
ddljob.DataSource = dt;
ddljob.DataTextField = "Job_Title";
ddljob.DataValueField = "Job_Id";
ddljob.DataBind();

}
 
Share this answer
 
Try This

@Html.DropDownListFor(model => model.xyz, new SelectList(new List<Object>{
new { key= "" , value = "Choose" },
new { key= 1 , value = "1" },
new { key= 2 , value = "2" },
new { key= 3 , value = "3" },
new { key= 4 , value = "4" }
}, "key", "Value",3), new { @class = "form-control" })
 
Share this answer
 
v2

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