views:

50

answers:

0

Hi I have come with following solution but I'm not sure if it's the best one. What I specially dislike is the way I have to apply the style in the DayRender event, any comments?

To overcome that problem what I did was to store the selected date in the viewstate and then reset the selected date. To preserve the marker on the selected date I apply the SelectedDayStyle to the matching Cell in the DayRender event of the calender.

Here the VB.NET code:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        ViewState("SelectedDate") = calKalender.SelectedDate
        calKalender.SelectedDate = Nothing 'We want to be able to select the current selected date again to close the calendar
End Sub

Private Sub calKalender_DayRender(ByVal sender As System.Object, ByVal e As WebControls.DayRenderEventArgs) Handles calKalender.DayRender
        If e.Day.Date = ViewState("SelectedDate") Then
            e.Cell.BackColor = calKalender.SelectedDayStyle.BackColor
            e.Cell.ForeColor = calKalender.SelectedDayStyle.ForeColor
            e.Cell.Font.Bold = calKalender.SelectedDayStyle.Font.Bold
        End If
End Sub

Regards