开发者

How to control style of today's cell in asp.net ajax CalendarExtender?

Based on the AjaxControlToolkit API for the CalendarExtender I can control the style of the selected date using:

.ajax__calendar_active { background-color:red }

And according to the API, I was hoping, that .ajax__calendar_today would allow me to control the style of today's table cell, if show. Unfortunately, this .ajax__calendar_today controls the style of the bigger "Today: XYZ" button at the bottom of the calendar.

Does anyone know how to style today's table cell, if/when displayed?

Update:

I inspected the HTML using Firebug and see that there is no special css class or other indicator for today's day cell. I guess that makes sense from a server side perspective... how to know what day it is on the user's machine, without adding code to ca开发者_如何学运维pture GMT offset and such.

So know I think that i am stuck creating some javascript to get today's date client side and comparing to each cell's title attribute, which is set to something like "Friday, February 11, 2011".

Update:Sept 2011 The latest AjaxControlToolkit release has added the .ajax__calendar_today css class to control this.


I believe you could use the following CSS class:

.ajax__calendar_today .ajax__calendar_day { background-color:red;}


Couldn't find a special class for this, so I wound up putting a style in my site.master. FYI, the padding 0 is because the border takes 2px, which is what default padding is set for.

<style type="text/css">
    div.ajax__calendar_day[title='<%=DateTime.Now.ToString("dddd, MMMM dd, yyyy")%>']
    {
    border: 1px solid #F00;
    padding-right: 0px;
    }
</style>


The best solution I found is this post.

I just removed the first 2 lines of the function (set current day) and fixed typo error in dayDIVs[i].style.bordercolor to dayDIVs[i].style.borderColor (uppercase C for color). You can also add dayDIVs[i].style.borderStyle = "dotted";

So here is the transcript of it (with my modifications):

/* In HEAD section */

<script type="text/javascript">
    function clientShown(sender, args) {
        var today = new Date();
        var currentTitle = today.localeFormat("D");
        //Find all the Day DIVs in the Calendar's daysBody
        var dayDIVs = sender._daysBody.getElementsByTagName("DIV");
        for (i = 0; i < dayDIVs.length; i++) {
            if (dayDIVs[i].title == currentTitle) {
                //Change the current day's style
                dayDIVs[i].style.borderColor = "#0066cc";
                dayDIVs[i].style.borderStyle = "dotted";
            }
        }
    }
</script>

/* and then in your BODY: */

<cc1:CalendarExtender ID="CE" runat="server" Enabled="True" TargetControlID="CalendarDateTextBox"
                        OnClientShown="clientShown" />


You need the following css class: .ajax_calendar .ajax_calendar_active .ajax__calendar_day {background-color:red;}

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜