DropDownList中的最大值 - ASP.NET

DropDownList中的最大值 - ASP.NET

问题描述:

如何通过C#获得ASP.NETDropDownList值的最大值?DropDownList中的最大值 - ASP.NET

是否有任何方法,或者我应该手动获取它?

int maxValue = DropDownList1.Items.Cast<ListItem>().Select(item => int.Parse(item.Value)).Max();

+0

谢谢。有用。 – MSajjadi 2012-04-09 08:10:36

DropDownList1.Items.Cast<ListItem>().Max(j => j.Value) // For string comparison 

或者,

DropDownList1.Items.Cast<ListItem>().Max(j => int.Parse(j.Value)) // If you want max int