Aspx日历:Page_Load和Btn_Click中的SelectedDate

时间:2012-01-24 06:20:42

标签: asp.net calendar

在Page_Load中,我从MySQL表中检索了一个Date数据类型变量,并将其显示在日历中,如下所示。

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim startdate As Date = objDBPromotion.getStartDateByPromoID(id)
startdateCalendar.VisibleDate = startdate
startdateCalendar.SelectedDate = startdate

在Btn_Click中,我希望能够点击日历中的其他日期,并且消息框将打印出所选的新日期。这就是我所做的。

Protected Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click

Dim selecteddate = startdateCalendar.SelectedDate.ToString()
MsgBox(selecteddate)

但是,消息框显示变量'startdate'的值。或者,SelectedDate的值没有改变。我该怎么做呢?

提前致谢。

1 个答案:

答案 0 :(得分:0)

尝试手动更新,如:

startdateCalendar.SelectedDate = DateTime.ParseExact(YourtextBox.Text, startdateCalendar.Format, null);
Dim selecteddate = startdateCalendar.SelectedDate.ToString()  
MsgBox(selecteddate)

我相信这会有效..