如何使用 radcalendar 保存和检索多个选定的日期

How to save and retrieve multiple selected dates using radcalendar

我想使用 RadCalendar 将多个 selected 日期保存到 sql 数据库 table 列,保存后,在页面加载时在 radcalender 中突出显示以下日期,并禁用休息radcalendar 中的日期:

我已经搜索过 radcalendar,但没有用。

我做了什么?

我使用 stringbuilder 将 radcalendar 上的 selected 多个日期存储到文本框中,如下所示:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        On Error Resume Next

        Dim stringbuilder As StringBuilder = New StringBuilder
        For Each selecteddate As RadDate In RadCalendar1.SelectedDates
            stringbuilder.Append(selecteddate.Date.ToString("dd-MMM-yyyy") + ", ")
        Next
        stringbuilder.Length -= 2
        TextBox1.Text = stringbuilder.ToString
    End Sub

当我在 radcalendar 中 select 多个日期并单击按钮时,上面的代码日期存储在文本框中:07-sep-2015,10-sep-2015, 2015 年 9 月 22 日等..动态

但问题是如何在页面加载时在 Radcalendar 中突出显示那些 selected 日期,

有人向我推荐了代码,但我不知道如何实现它

   Dim d = New RadDate()
    d.Date = New DateTime(textbox1.text)
    RadCalendar1.SelectedDates.Add(d)

这对我来说适用于 C#。下面是我使用在线代码转换器转换的 VB.NET...从下面的示例中获取您需要的内容以使其在您的场景中工作。

C#

protected void Page_Load(object sender, EventArgs e)
{
    HighlightDates();
}

private void HighlightDates()
{
    TextBox1.Text = "07-sep-2015, 10-sep-2015, 22-sep-2015"; // you probably won't need to do this if you're populating the textbox already
    var dates = TextBox1.Text.Replace(" ", "").Split(',');
    foreach (var d in dates)
        RadCalendar1.SelectedDates.Add(new RadDate(Convert.ToDateTime(d)));
}

VB.NET

Protected Sub Page_Load(sender As Object, e As EventArgs)
    HighlightDates()
End Sub

Private Sub HighlightDates()
    TextBox1.Text = "07-sep-2015, 10-sep-2015, 22-sep-2015" ' you probably won't need to do this if you're populating the textbox already
    Dim dates = TextBox1.Text.Replace(" ", "").Split(","C)
    For Each d As String In dates
        RadCalendar1.SelectedDates.Add(New RadDate(Convert.ToDateTime(d)))
    Next
End Sub

要禁用突出显示的日期以外的所有其他日期,请在 aspx 中将 OnDayRender="RadCalendar1_DayRender" 添加到您的 RadCalendar,然后在后面使用此代码。

Protected Sub RadCalendar1_DayRender(sender As Object, e As DayRenderEventArgs)
    txtDates.Text = "07-sep-2015, 10-sep-2015, 22-sep-2015"
    ' you probably won't need to do this
    Dim sDates = txtDates.Text.Replace(" ", "").Split(","C)
    Dim dates = New List(Of DateTime)()
    For Each d As String In sDates
        dates.Add(Convert.ToDateTime(d))
    Next

    If Not dates.Contains(e.Day.[Date]) Then
        Dim calendarDay = New RadCalendarDay()
        calendarDay.[Date] = e.Day.[Date]
        calendarDay.IsSelectable = False
        RadCalendar1.SpecialDays.Add(calendarDay)
    End If
End Sub