Translate

jueves, 27 de febrero de 2014

ASP.NET: Populating DropdownList with data from two tables using Entity Framework

This time we are going to populate a DropdownList with data from two differents tables. The tables were implemented using  Entity Framework code first. Those are the tables from which we are going to extract the data. We need the Id and the Name from the RaceTypes table, and the name from the Sports Tables.


This is the DropdownList showing the Name from the Sports, and the Name from the RaceTypes. Once you select a value from the DropDownList it would return the correspondet Id from the RaceTypes.
 

This is the code for the DropDownList. We use the field SelectMethod to indicate wich method are we going to use to populate data, DataTextField to indicate which data are we going to show, and DataValueField to indicate wich value return.




And this is the code behind with the method used to retrieve data.





No hay comentarios: