Ik zie nog best vaak, dat programmeurs datum gerelateerde comboboxjes vullen met ingetypte data.
Dit voorbeeld is lekker flexibel en werkt mee met de UICulture in
web.Config
< globalization uiCulture="nl-nl"/>
using System;
using System.Collections.Generic;
using System.Web;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Threading;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
int monthNumber = 0;
var myMonthnames = Thread.CurrentThread.CurrentUICulture.DateTimeFormat.MonthNames
.Select(p => new { monthNo = ++monthNumber, monthName = p.ToLower() });
ddlMonthnames.DataTextField = "monthName";
ddlMonthnames.DataValueField = "monthNo";
ddlMonthnames.DataSource = myMonthnames;
ddlMonthnames.DataBind();
}
}
Het resultaat in HTML ziet er zo uit.
<select name="ddlMonthnames" id="ddlMonthnames">
<option value="1">januari</option>
<option value="2">februari</option>
<option value="3">maart</option>
<option value="4">april</option>
<option value="5">mei</option>
<option value="6">juni</option>
<option value="7">juli</option>
<option value="8">augustus</option>
<option value="9">september</option>
<option value="10">oktober</option>
<option value="11">november</option>
<option value="12">december</option>
<option value="13"></option>
</select>
|