Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
295
Retrieve Weeknumber
posted

How can I retrieve the week number for a selected date based on the week rule property? I've been through the documentation and intellisense and cannot find anything that works.

 

Thanks.

  • 8160
    posted

    Hi nhutchinson,

    this should be working:

        <title></title>
        <script language="javascript" type="text/javascript">
    // <![CDATA[
    
            function Button1_onclick() {
                var wmc = $find('WebMonthCalendar1');
                var selectedDay = wmc.get_selectedDate();
                var days = wmc.get_days();
                var weekNumber;
    
                for (var i = 0; i < days.length; i++) {
                    if (days[i].isSelected()) {
                        weekNumber = days[42 + Math.floor(i / 7)].get_weekNumber();
                    }
                }
            }
    
    // ]]>
        </script>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
            <ig:WebScriptManager ID="WebScriptManager1" runat="server">
            </ig:WebScriptManager>
            <ig:WebMonthCalendar ID="WebMonthCalendar1" runat="server" SelectionType="Single"
                OnSelectedDateChanged="WebMonthCalendar1_SelectedDateChanged" WeekRule="FirstFourDayWeek"
                EnableWeekNumbers="true">
            </ig:WebMonthCalendar>
        </div>
        </form>
        <p>
            <input id="Button1" type="button" value="button" onclick="return Button1_onclick()" /></p>
    </body>
    </html>
    

    The get_days() returns array of visible days-cells in calendar, where first 42 items represent days. If application enables week numbers, then following 6 items represent week-number cells.
    The properties of days and week numbers are different. For example, month-days have get_day/month/year/dow and other methods like isSelected/isWeekend/isFocus, but they are not week-numbers and that property and returns -1. The week numbers on other hand, do not have day-related properties and those methods return -1. But they have get_weekNumber. So, if application wants to check week-number displayed by a row where a month-day is located, then it may use following: weekNumber = days[42 + Math.floor(i / 7)].get_weekNumber();

     

    http://help.infragistics.com/NetAdvantage/ASPNET/2011.2/CLR4.0/?page=Web_WebMonthCalendar.html