Click here to Skip to main content
15,895,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
hi to all,
Here i done how to set default value as per(Brent Jenkins) ideas and tricks.thanks for that. Now i want to set default values for drop down for country

DESCRIPTION:
Here there r so many countries but i want india is default country
Here my code:-
IN Entities model

C#
[Required]

       public int Country_Id { get; set; }



IN controller:-

XML
List<SelectListItem> list = new List<SelectListItem>();
            list.Add(new SelectListItem { Text = "Select Country", Value = "Select Country" });//set default text for DropdownList
            var cat = (from c in db.Country select c).ToArray();//get data from database using linq
            for (int i = 0; i < cat.Length; i++)
            {
                list.Add(new SelectListItem { Text = cat[i].Country_Name, Value = cat[i].Country_Id.ToString() });
            }
            ViewData["ViewCountry"] = list;


How to set default value in entities model.CAn you explain me detail
Posted

You can refer this

three-ways-to-populate-selected-value.html[^]

Hope it will help...
 
Share this answer
 
Comments
JOTHI KUMAR Member 10918227 8-Aug-14 3:05am    
here subject give static but i'm using database table for country
here is the format

HTML
Html.DropDownListFor("yourid",new SelectList("drop down values"),"selected value")


if u already know Country_Id(india),just hard code it on "selected value"
 
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