在多个日历上设置日期时遇到问题:VS2010 [英] having trouble setting date on multiple calendars: VS2010

查看:83
本文介绍了在多个日历上设置日期时遇到问题:VS2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我无法在日历上设置日期.我有2个日历,当用户在日历1上选择一天时,我希望日历2的选定日期为日历1的日期+ 364天.

因此,如果cal.1是:11/27/2012,那么cal.2是:11/26/2013.我在这里有一些代码,当我只设置calendar2.selecteddate = calendar1.selecteddate时它起作用,但是当我添加以下代码时它不起作用.

I am having some trouble setting a date on the calendar. I have 2 calendars, when the user selects a day on calendar 1, I want calendar 2''s selected date to be calendar 1''s date + 364 days.

So if cal.1 is: 11/27/2012 then cal.2 is: 11/26/2013. I have some code here it works when i just set calendar2.selecteddate = calendar1.selecteddate, but not when i add the following code.

Protected Sub Calendar1_SelectionChanged(sender As Object, e As EventArgs)
    Dim calendar1 As Calendar = CType(AgreeForm.FindControl("Calendar1"), Calendar)
    Dim calendar2 As Calendar = CType(AgreeForm.FindControl("Calendar2"), Calendar)

    calendar2.SelectedDate = calendar1.SelectedDate.AddDays("364")
End Sub



有人可以给我一些帮助吗?
两者都在formview上.



can anyone give me some help with this?
both are on a formview.

推荐答案

而不是添加天数",因为我相信您总是希望来年的前一天,并且需要考虑到飞跃年,也许您可​​以尝试这种方法.我认为您的主要错误是您正在向.AddDays发送一个字符串,而不是该方法想要的double.

只需调试代码的每一行,并确保正在发生的事情正在发生.如果当您尝试将dtForCalendar2分配给calendar2.SelectedDate时是正确的,则问题可能出在您的calendar2标记上.您可以使用改进问题小部件并将该标记也添加到您的问题吗?
Instead of the Add days, because I believe you always want the day previous in the coming year and you need to take into account leap years, perhaps you can try this approach. I think your main error is that you are sending in a string to .AddDays instead of a double as the method wants.

Just debug through each line of the code and ensure that what is supposed to be happening, is happening. If dtForCalendar2 is correct when you try to assign it to calendar2.SelectedDate, then the issue may be with your calendar2 markup. Could you use the improve question widget and add that markup to your question as well?
DateTime dtForCalendar2 = calendar1.SelectedDate
dtForCalendar2 = dtForCalendar2.AddYears(1.0)
dtForCalendar2 = dtForCalendar2.AddDays(-1.0)
calendar2.SelectedDate = dtForCalendar2


这对我有用:
This worked for me:
Protected Sub Calendar1_PreRender(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.PreRender
    Calendar2.SelectedDate = Calendar1.SelectedDate.Date.AddDays(364)
    Calendar2.VisibleDate = Calendar2.SelectedDate
End Sub


这篇关于在多个日历上设置日期时遇到问题:VS2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆