protected void BindMonthList(DropDownList ddl) { var monthList = System.Globalization.DateTimeFormatInfo.InvariantInfo.MonthNames.Select((item, index) => new { Month = item, Value = index+1 }); ddl.DataSource = monthList; ddl.DataTextField = "Month"; ddl.DataValueField = "Value"; ddl.DataBind(); }
if (this.ddlMesi.Items.Count <= 0) for (int i = 1; i <= 12; i++) { ddlMesi.Items.Add(new ListItem( System.Globalization.DateTimeFormatInfo.CurrentInfo.GetMonthName(i), i.ToString() )); }
DateTimeFormatInfo
int iVal = ComboBox.SelectedIndex + 1; //if you select February, returns 2
private void Form1_Load(object sender, EventArgs e) { var months = System.Globalization.DateTimeFormatInfo.InvariantInfo.MonthNames; comboBox1.DataSource = months; }
MonthNames
protected void Page_Load(object sender, EventArgs e) { var months = System.Globalization.DateTimeFormatInfo.InvariantInfo.MonthNames; DropDownList1.DataSource = months; DropDownList1.DataBind(); }
Dim i As Integer = 1 Do While i <= 12 myvar = MonthName(i, True) cboToMonth.Items.Add(New ListItem(myvar, i)) i = i + 1 Loop
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)