GridDateTimeColumn Special Days

5 posts, 1 answers
  1. Michael O'Flaherty
    Michael O'Flaherty avatar
    67 posts
    Member since:
    Jun 2010

    Posted 23 May 2013 Link to this post

    Hi!

    When we display a RadDatePicker control (see attached #1), we are able to add a special day of "today" using this code:
    <telerik:RadDatePicker ID="radDatePickerBirthdateSearchCriteria" MinDate="1/1/1900" runat="server">
        <Calendar ShowRowHeaders="false" runat="server">
            <SpecialDays
                <telerik:RadCalendarDay Repeatable="Today"
                    <ItemStyle CssClass="rcToday" /> 
                </telerik:RadCalendarDay
            </SpecialDays
        </Calendar>
    </telerik:RadDatePicker>

    However, when we display a grid column using this code:
    <telerik:GridDateTimeColumn EnableTimeIndependentFiltering="true" DataField="Birthdate" DataFormatString="{0:MM/dd/yyyy}"  HeaderText="Birthdate" SortExpression="Birthdate" UniqueName="Birthdate">
    </telerik:GridDateTimeColumn>

    protected void radGridResults_ItemCreated(object sender, GridItemEventArgs e)
            {
                if (e.Item is GridFilteringItem)
                {
                    GridFilteringItem filteringItem = e.Item as GridFilteringItem;
     
                    RadDatePicker radDatePicker = (RadDatePicker)filteringItem["Birthdate"].Controls[0];
                    radDatePicker.EnableEmbeddedSkins = true;
                    radDatePicker.Skin = "Office2010Blue";
                    radDatePicker.CssClass = "radDatePicker radGridFilterDatePicker";
                    radDatePicker.SharedCalendar.ShowRowHeaders = false;
                    Button buttonDatePickerFilter = (Button)filteringItem["Birthdate"].Controls[2];
                    buttonDatePickerFilter.CssClass = "rgFilter radGridFilterDatePickerFilterButton";
                    RadCalendarDay radCalendarDayToday = new RadCalendarDay();
                    radCalendarDayToday.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;
                    radCalendarDayToday.ItemStyle.CssClass = "rcToday";
                    radDatePicker.Calendar.SpecialDays.Add(radCalendarDayToday);
                }
            }


    When we add the special day in code behind, it does not display properly when we are displaying the calendar as a filter (see attached #2.)

    Are we doing something wrong? How can we accomplish this?

    Thanks!
  2. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 May 2013 Link to this post

    Hi,

    Here is the sample code snippet I tried which worked as expected.

    C#:
    protected void RadGrid1_ItemDataBound(object sender, Telerik.Web.UI.GridItemEventArgs e)
    {
        if (e.Item is GridFilteringItem)
        {
            GridFilteringItem filteringItem = (GridFilteringItem)e.Item;
            RadDatePicker datepicker = (RadDatePicker)filteringItem["Birthdate"].Controls[0];
            datepicker.EnableEmbeddedSkins = true;
            datepicker.Skin = "Office2010Blue";
            datepicker.CssClass = "radDatePicker radGridFilterDatePicker";
            datepicker.SharedCalendar.ShowRowHeaders = false;
            Button buttonDatePickerFilter = (Button)filteringItem["Birthdate"].Controls[2];
            buttonDatePickerFilter.CssClass = "rgFilter radGridFilterDatePickerFilterButton";
            RadCalendarDay NewDay = new RadCalendarDay();
            NewDay.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;
            NewDay.ItemStyle.BackColor = System.Drawing.Color.Bisque;
            datepicker.SharedCalendar.SpecialDays.Add(NewDay);
        }  
    }

    Thanks,
    Shinu.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Michael O'Flaherty
    Michael O'Flaherty avatar
    67 posts
    Member since:
    Jun 2010

    Posted 24 May 2013 Link to this post

    Hmmm... Still no go. I took out the styles just to make sure. C1 is from the grid filter and C2 is from a page. Does the calendar inherit any styles from the grid? Something external must be affecting this. AJAX?

    RadDatePicker radDatePicker = (RadDatePicker)filteringItem["Birthdate"].Controls[0];
                    radDatePicker.EnableEmbeddedSkins = true;
                    //radDatePicker.Skin = "Office2010Blue";
                    //radDatePicker.CssClass = "radDatePicker radGridFilterDatePicker";
                    radDatePicker.SharedCalendar.ShowRowHeaders = false;
                    Button buttonDatePickerFilter = (Button)filteringItem["Birthdate"].Controls[2];
                    //buttonDatePickerFilter.CssClass = "rgFilter radGridFilterDatePickerFilterButton";
                    RadCalendarDay radCalendarDayToday = new RadCalendarDay();
                    radCalendarDayToday.Repeatable = Telerik.Web.UI.Calendar.RecurringEvents.Today;
                    radCalendarDayToday.ItemStyle.BackColor = System.Drawing.Color.Bisque;
                    //radCalendarDayToday.ItemStyle.CssClass = "rcToday";
                    radDatePicker.Calendar.SpecialDays.Add(radCalendarDayToday);
  5. Answer
    Venelin
    Admin
    Venelin avatar
    352 posts

    Posted 28 May 2013 Link to this post

    Hi Michael,

    The only thing you need to do is to replace this line of code:

    radDatePicker.Calendar.SpecialDays.Add(radCalendarDayToday)

    with this:

    radDatePicker.SharedCalendar.SpecialDays.Add(radCalendarDayToday);

    I am also attaching a sample runnable project.

    Regards,
    Venelin
    Telerik
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  6. Michael O'Flaherty
    Michael O'Flaherty avatar
    67 posts
    Member since:
    Jun 2010

    Posted 28 May 2013 Link to this post

    I keep forgetting about the SharedCalendar vs. Calendar. Not sure I understand why you have it that way, but it works--thanks!
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017