Radcalendar default to today

4 posts, 0 answers
  1. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 15 Mar 2012 Link to this post

    How can I make RadDatePicker default to today's date when opens it? My RadDatePicker is one of the column the grid, when I do filter, I like to open the raddatePicker with today's date highlighted.

    I am using  2011 Q1.  Is the newest version already set today's date as default when open the calendar?

    Thanks
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 16 Mar 2012 Link to this post

    Hello,

    Try the following code in ItemDataBound event to highlight today's date.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridFilteringItem)
     {
        GridFilteringItem item = (GridFilteringItem)e.Item;
        RadDatePicker pkr = (RadDatePicker)item["BirthDate"].Controls[0];
        pkr.SelectedDate = DateTime.Now;
     }
    }

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. JJ
    JJ avatar
    147 posts
    Member since:
    May 2010

    Posted 18 Mar 2012 Link to this post

    Thanks Princy.

    What  I need is only have the today's date highlighted when open the raddatepick, but do not have the filter fill today's date.

    if i use pkr.SelectedDate = DateTime.Now;, today's date will also be filled at filter area.
    How can I have today's date highlighted on the calendar itself but wihout today's date filled as a selection in the filler area?

    Thanks
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 19 Mar 2012 Link to this post

    Hello,

    Try the following code to achieve your scenario.
    C#:
    protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
    {
     if (e.Item is GridFilteringItem)
     {
       GridFilteringItem item = (GridFilteringItem)e.Item;
       RadDatePicker pkr = (RadDatePicker)item["BirthDate"].Controls[0];
       RadCalendarDay NewDay = new RadCalendarDay();
       NewDay.Repeatable = RecurringEvents.Today;
       NewDay.ItemStyle.BackColor = System.Drawing.Color.Red;
       pkr.SharedCalendar.SpecialDays.Add(NewDay);  
     }
    }

    Thanks,
    Princy.
Back to Top