首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >如何使用雷达日历保存和检索多个选定日期

如何使用雷达日历保存和检索多个选定日期
EN

Stack Overflow用户
提问于 2015-09-09 10:25:06
回答 1查看 1.2K关注 0票数 0

我希望使用RadCalendar将多个选定日期保存到列,并在保存之后,在页面加载的radcalender中突出显示下列日期,并禁用雷达日历中的休息日期:

我查过雷达历法,但没有什么有用的。

我做了什么?

我已经将选定的多个日期存储在rad日历上,并使用字符串生成器将所选日期存储到文本框中:

代码语言:javascript
运行
复制
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

当我在雷达日历中选择多个日期并单击按钮为:07-9月-2015年、10-9月-2015年、22-9月-2015年等时,上述代码日期存储在文本框中。动态

但问题是,当页面加载时,如何突出显示Radcalendar中选定的日期,

有人建议我代码,但我不知道如何实现

代码语言:javascript
运行
复制
   Dim d = New RadDate()
    d.Date = New DateTime(textbox1.text)
    RadCalendar1.SelectedDates.Add(d)
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-09-10 06:06:15

在C#里,这对我来说很管用。下面是我用在线代码转换器转换的VB.NET .从下面的例子中拿出您需要的东西,让它在您的场景中工作。

C#

代码语言:javascript
运行
复制
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

代码语言:javascript
运行
复制
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

若要禁用除高亮度日期以外的所有其他日期,请将OnDayRender="RadCalendar1_DayRender"添加到aspx中的RadCalendar中,然后使用后面的代码。

代码语言:javascript
运行
复制
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
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/32477038

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档