Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
List<VentureLocation> _locationList = new List<VentureLocation>();

i added data from database to list.list is having 2 cloums id,location now.these records is taken in view bag
i.e,
 ViewBag.leftcontent=_locationList;
return PartialView(_locationList);

then how to add this data to dropdownlist id as datavalue field and location as datatext filed.
please reply me
Posted
Comments
SwarupDChavan 11-Mar-14 4:47am    
http://www.itorian.com/2013/02/dropdownlist-helper-data-binding-in-mvc.html

1 solution

you can write like this...

C#
ViewBag.leftcontent= New SelectedList(_locationList,"Id","location","<yourdefaultlocationtoselect>");</yourdefaultlocationtoselect>
 
Share this answer
 
Comments
laxmi smiley 11-Mar-14 5:48am    
if (itemVenture.VentureLocationID.Equals(itemLoc.VentureLocationID))
{ List<venturelocation> _locationList = new List<venturelocation>();
_locationList.Add(new VentureLocation{Text=itemLoc.VentureLocationID,value=itemLoc.VentureLocationName});
} error is add method has invalid arguments.
does not contain defnition for Text,value

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