绑定IEnumerable< T>下载ascx [英] Bind a IEnumerable<T> to dropdown in ascx

查看:56
本文介绍了绑定IEnumerable< T>下载ascx的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有一个通用的IEnumerable,比如IENumerable< student>每个列表包含学生ID,学生姓名,学生年龄。



我想将其绑定到下拉列表。



下拉列表必须显示学生姓名选择学生并单击按钮后,我必须能够将学生ID添加为查询字符串并获取详细信息并在另一个中显示详细信息。



如何我可以做到这一点吗?我在google搜索期间发现我可以直接将IEnumerable绑定到ddl。



谢谢

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

推荐答案

尝试如下...

Try like below...
yourDropDownList.DataSource = students.ToList();
yourDropDownList.DataTextField = "StudentName";
yourDropDownList.DataValueField = "StudentID";
yourDropDownList.DataBind();


这篇关于绑定IEnumerable&lt; T&gt;下载ascx的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆