开发者

asp.net dropdown datasource [duplicate]

开发者 https://www.devze.com 2023-04-11 08:10 出处:网络
This question already has answers here: Closed 11 years ago. Possible Duplicate: Converting Enumerable.Range to a List of Strings
This question already has answers here: Closed 11 years ago.

Possible Duplicate:

Converting Enumerable.Range to a List of Strings

In ASP.NET how do I populate a drop down list and also include text for the default selected state?

For eg.

A drop down will contain: Enter day, 1, 2, 3, 4, 5

ddlDayDropDown.DataSource = Enumerable.Range(1开发者_如何学Go, 31).ToList();
ddlDayDropDown.DataBind();

I can't add a "string" here.


Try ddlDayDropDown.Items.Insert(0, new ListItem("Enter day"));


ddlDayDropDown.DataSource = new string[] { "Enter day" }
  .Concat(Enumerable.Range(1, 31).Select(n => n.ToString()));
ddlDayDropDown.DataBind();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号