开发者

Easier way to get last item in Dropdownlist

There's got to be an easier way to do what I came up with here:

int lastDayIn开发者_JAVA技巧List = ddlBirthDay.Items.IndexOf(ddlBirthDay.Items[ddlBirthDay.Items.Count -1]);


This will give you the last item in a drop down list.

ListItem lastItem = ddlBirthDay.Items[ddlBirthDay.Items.Count-1]

In your code, it looks like you are getting the index of the last item. However, the accessible index of the last item will be -1 of the count.


If you are using .net v3.5 then Linq is an option, too.

ListItem latItem = ddlBirthday.Items.Last();
ListItem latItem = ddlBirthday.Items.LastOrDefault();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜