Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi,

I have a generic IEnumerable, say IENumerable<student> and each list contains student ID, student Name, Student Age.

I want to bind this to a dropdown list.

The dropdown list must show the student name and after selecting a student and click a button, i must be able to add the student id as query string and fetch the details and show the details in another.

How can i achieve this. I found out during my googling that i can just bind IEnumerable to ddl directly.

Thanks
Posted

1 solution

Try like below...
C#
yourDropDownList.DataSource = students.ToList();
yourDropDownList.DataTextField = "StudentName";
yourDropDownList.DataValueField = "StudentID";
yourDropDownList.DataBind();
 
Share this answer
 
Comments
Arjun Menon U.K 7-Jul-14 5:29am    
Thanks Tadit. I found out by experimenting.. ANyway thanks a lot for replying...:)
Most welcome. :)

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