【问题标题】:How to add or subtract dates in C# using ajax calendar extender?如何使用 ajax 日历扩展器在 C# 中添加或减去日期?
【发布时间】:2012-10-22 06:53:49
【问题描述】:

我有两个使用 ajax 日历扩展器的文本框。当我从一个文本框中选择一个日期时,它应该通过添加一些天或月来自动填充另一个文本框。

我该怎么做?

【问题讨论】:

  • 请大家帮帮我,我是 C# 的初学者...
  • 请发布一些代码,显示您当前已实现的内容。
  • Umar 您需要在 .NET 中搜索 DateTime,然后使用 DateTime.Add 方法。您可以添加天、年、月等。

标签: asp.net .net c#-3.0


【解决方案1】:

请按照此示例修改您的代码。希望对您有所帮助。

<asp:UpdatePanel id="UpdatePanel1" runat="server">
<contenttemplate>
<cc2:CalendarPopup id="CalendarExtender1" runat="server" Width="71px" OnDateChanged="CalendarPopup1_DateChanged" AutoPostBack="True"></cc2:CalendarPopup>
<cc2:CalendarPopup id="CalendarExtender2" runat="server" Width="71px"></cc2:CalendarPopup>
</contenttemplate>
</asp:UpdatePanel>        

**Code behind:**

 protected void CalendarPopup1_DateChanged(object sender, EventArgs e)
    {
        CalendarPopup2.SelectedDate = CalendarPopup1.SelectedDate.AddDays(1); // you can add the number of days you want
    } 

此外,以下链接可能会让您对该主题有更好的了解:

http://www.dotnetcurry.com/ShowArticle.aspx?ID=149

【讨论】:

    猜你喜欢
    • 2012-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-09-17
    • 1970-01-01
    • 2016-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多