[英]Drop Down List in ASP.Net, how to bind it to a property of a list
I have drop down list which need to take all the values from the property Items which are stored in List< Person>
. 我有一个下拉列表,需要从存储在List< Person>
Items属性中获取所有值。 My var model is accepting all the information from my list
. 我的var模型正在接受list
所有信息。
string text=File.ReadAllText(@"...");
List< Person > model = JsonConvert.DeserializeObject< List< Person>>(text)
my drop down list code: 我的下拉列表代码:
< asp:DropDownList runat="server" ID="dpdTags" >
So how I can bind the needed data to the drop down list? 那么如何将所需的数据绑定到下拉列表?
dpdTags.DataSource = model;
dpdTags.DataTextField = "PersonText";
dpdTags.DataValueField = "PersonValue";
dpdTags.DataBind();
Try use this 试试这个
i think it is useful for you 我认为这对您有用
List<Person> people = GetDataFromSomewhere();
DropDownList ddl = new DropDownList();
ddl.DataTextField = "Name";
ddl.DataValueField = "Id";
ddl.DataSource = people;
ddl.DataBind();
ddl.SelectedValue = (from p in people
where p.Selected == true
select p.Id).FirstOrDefault().ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.