怎样修改服务器日期控件,如何:在 Calendar Web 服务器控件中以编程方式设置当前日期...

此博客展示了如何在Web应用程序中使用VB.NET和C#设置日历控件,将当前日期设为明天,并根据用户在下拉列表中的选择更新日历的今天日期。代码示例包括在页面加载时填充下拉列表,以及当用户更改选择时更新日历控件的日期。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

下面的示例将 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);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值