Published:

Populate ASP.NET dropdown list with month names using LINQ

Using LINQ and the Enumerable.Range method it's possible to populate a dropdown list of month names in a single line.

ddlMonth.Items.AddRange(
    Enumerable.Range(1, 12)
    .Select(x => new ListItem { 
        Text = new DateTimeFormatInfo().GetAbbreviatedMonthName(x), 
        Value = x.ToString() 
    }).ToArray());

 


Subscribe or Follow Me For Updates

Subscribe to my YouTube channel or follow me on Twitter, Facebook or GitHub to be notified when I post new content.

Other than coding...

I'm currently attempting to travel around Australia by motorcycle with my wife Tina on a pair of Royal Enfield Himalayans. You can follow our adventures on YouTube, Instagram and Facebook.


Need Some ASP.NET Help?

Search fiverr to find help quickly from experienced ASP.NET developers.



Supported by