显示周数在ASP:日历 [英] Show week numbers in asp:Calendar

查看:160
本文介绍了显示周数在ASP:日历的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有表现出一个asp的周数更简单的方法:日历控件?
我发现这个职位,但它是一个2008年后。认为有可能是一个更简单的方法呢?

Is there an easier way to show the week numbers in an asp:Calendar control? I found this post but it is a 2008 post. Thought there might be a simpler way now?

我在asp.net开发C#4.0。

I am developing in asp.net c# 4.0.

感谢

推荐答案

我设法使该code工作改变周太,这里是code:

I have managed to make that code work for changing the weeks too, here is the code:

protected void Page_Load(object sender, EventArgs e)
      {
         if (!Page.IsPostBack)
           {
               eventsDayView.DataLoad(DateTime.Now);
               calendar.SelectedDate = DateTime.Now;
               calendar.TodaysDate = DateTime.Now;
               calendar.VisibleDate = DateTime.Today;
               addWeekNumberColumn();
            }
      }
private void addWeekNumberColumn()
      {
        // Get the date shown in the calendar control
        DateTime curMonth = calendar.VisibleDate;

        // Find first day of the current month
        curMonth = Convert.ToDateTime(curMonth.Year.ToString() + "-" + curMonth.Month.ToString() + "-01");

        // Build javascript
        string jscript = "<script type='text/javascript'> addWkColumn('" + calendar.ClientID + "', " + getISOWeek(curMonth).ToString() + ");</script>";

         // Add script to page for execution of addWkColumn javascript function
         Page.ClientScript.RegisterStartupScript(this.GetType(), "AddWeeknumbers", jscript);
     }
     // Helper function to find ISO week
private int getISOWeek(DateTime day)
      {
        return System.Globalization.CultureInfo.CurrentCulture.Calendar.GetWeekOfYear(day, System.Globalization.CalendarWeekRule.FirstFourDayWeek, DayOfWeek.Monday);
      }
protected void calendar_OnVisibleMonthChanged(object sender, MonthChangedEventArgs e)
    {
       calendar.VisibleDate = e.NewDate;
       addWeekNumberColumn();
    }


<script type="text/javascript">
        function addWkColumn(tblId, wkStart) {
            var tbl = document.getElementById(tblId);
            var tblBodyObj = tbl.tBodies[0];
            for (var i = 0; i < tblBodyObj.rows.length; i++) {
                // Month Header
                if (i == 0) {
                    // Add extra colspan column
                    tblBodyObj.rows[i].cells[0].colSpan = 8;
                }
                // Week Header
                if (i == 1) {
                    // Add week column headline
                    var newCell = tblBodyObj.rows[i].insertCell(0);
                    newCell.innerHTML = 'wk';
                    newCell.style.fontSize = '8px';
                    newCell.style.fontWeight = 'bold';
                    newCell.style.verticalAlign = 'bottom';
                    newCell.style.backgroundColor = '#ffffee';
                }
                // Normal row
                if (i >= 2) {
                    // Add the weeknumbers 
                    var newCell = tblBodyObj.rows[i].insertCell(0);
                    newCell.innerHTML = wkStart;
                    wkStart += 1;
                    if (wkStart == 53) {
                        wkStart = 1;
                    }
                    newCell.style.fontSize = '8px';
                    newCell.style.backgroundColor = '#ffffee';
                }
            }
        }
    </script>

<asp:Calendar ID="calendar" runat="server" Font-Names="Tahoma" Font-Size="11px" NextMonthText="&raquo;"
                                                    PrevMonthText="&laquo;" SelectMonthText="&raquo;" SelectWeekText="&rsaquo;" CssClass="myCalendar"
                                                    BorderStyle="None" CellPadding="1" OnSelectionChanged="calendar_SelectionChanged" OnDayRender="calendar_dayrender"
                                                    meta:resourcekey="calendarResource1" FirstDayOfWeek="Monday" OnVisibleMonthChanged="calendar_OnVisibleMonthChanged">
                                                    <DayHeaderStyle CssClass="myCalendarDayHeader" />
                                                    <DayStyle CssClass="myCalendarDay" />
                                                    <NextPrevStyle CssClass="myCalendarNextPrev" />
                                                    <OtherMonthDayStyle ForeColor="Gray" />
                                                    <SelectedDayStyle Font-Bold="True" />
                                                    <SelectorStyle CssClass="myCalendarSelector" />
                                                    <TitleStyle CssClass="myCalendarTitle" />
                                                    <TodayDayStyle ForeColor="Red" Font-Bold="True" />
                                                </asp:Calendar>

这篇关于显示周数在ASP:日历的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆