下面的示例将 TodaysDate 设置为“tomorrow”(明天),然后将 SelectedDate 设置为 TodaysDate。在浏览器中,对应于“tomorrow”(明天)的日期将突出显示。
Dim tomorrow As Date = Date.Today.AddDays(1)
Calendar1.TodaysDate = tomorrow
Calendar1.SelectedDate = Calendar1.TodaysDate
DateTime tomorrow = DateTime.Today.AddDays(1);
Calendar1.TodaysDate = tomorrow;
Calendar1.SelectedDate = Calendar1.TodaysDate;
下面的示例演示如何用选择的日期填充 DropDownList 控件并根据用户在列表中的选择设置“日历”控件中的当天日期值。
Protected Sub Page_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
If Not IsPostBack Then
Dim today As DateTime = System.DateTime.Today
Dim yesterday As DateTime = today.AddDays(-1)
Dim tomorrow As DateTime = today.AddDays(1)
DropDownList1.items.Add(String.Format("{0:dd MMM yyyy}", _
today))
DropDownList1.items.Add(String.Format("{0:dd MMM yyyy}", _
yesterday))
DropDownList1.items.Add(String.Format("{0:dd MMM yyyy}", _
tomorrow))
End If
End Sub
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender _
As Object, ByVal e As System.EventArgs) _
Handles DropDownList1.SelectedIndexChanged
Calendar1.TodaysDate = _
Date.Parse(DropDownList1.SelectedItem.Text)
End Sub
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DateTime today = System.DateTime.Today;
DateTime yesterday = today.AddDays(-1);
DateTime tomorrow = today.AddDays(1);
DropDownList1.Items.Add(String.Format("{0:dd MMM yyyy}",
today));
DropDownList1.Items.Add(String.Format("{0:dd MMM yyyy}",
yesterday));
DropDownList1.Items.Add(String.Format("{0:dd MMM yyyy}",
tomorrow));
}
}
protected void DropDownList1_SelectedIndexChanged(object sender,
EventArgs e)
{
Calendar1.TodaysDate =
DateTime.Parse(DropDownList1.SelectedItem.Text);
}