zoukankan      html  css  js  c++  java
  • asp.net像博客园一样的Calendar(日期控件)

    code:(页面)

     

    后台:

      int preMonth, curMonth, nextMonth;
            int[] preMonthArray, curMonthArray, nextMonthArray;


           /// <summary>
           /// 跟数据库的操作
           /// </summary>
           /// <param name="year"></param>
           /// <param name="month"></param>
           /// <returns></returns>
            private int[] getArray(int year, int month)
            {
                int[] array = new int[31];
                int i;
                for (i = 0; i < 31; i++)
                    array[i] = 0;
                i = 0;
              //这里读数据库赋值给arry
                while (i>=0&&i<5)
                {
                    array[i++] = i+1;
                }
             
                return array;
            }

          
            protected void test_DayRender(object sender, DayRenderEventArgs e)
            {

                CalendarDay day = e.Day; //得到年月日等信息
                TableCell cell = e.Cell;

                preMonth = day.Date.Month;
                curMonth = (preMonth + 1 > 12) ? 1 : (preMonth + 1);
                nextMonth = (curMonth + 1 > 12) ? 1 : (curMonth + 1);

                curMonthArray = getArray(day.Date.Year, curMonth);
                preMonthArray = getArray(day.Date.Year, preMonth);
                nextMonthArray = getArray(day.Date.Year, nextMonth);

                int j = 0;
                if (day.Date.Month.Equals(preMonth))
                {
                    while (preMonthArray[j] != 0)
                    {
                        if (day.Date.Day == preMonthArray[j])
                        {
                            cell.Controls.Clear();
                            cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red;text-decoration:underline ' target='_self' >" + day.Date.Day.ToString() + "</a>"));
                        }
                        j++;
                    }

                }
                else if (day.Date.Month.Equals(nextMonth))
                {
                    while (nextMonthArray[j] != 0)
                    {
                        if (day.Date.Day == nextMonthArray[j])
                        {
                            cell.Controls.Clear();
                            cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red ;text-decoration:underline' target='_self' >" + day.Date.Day.ToString() + "</a>"));
                        }
                        j++;
                    }

                }
                else if (day.Date.Month.Equals(curMonth))
                {
                    while (curMonthArray[j] != 0)
                    {
                        if (day.Date.Day == curMonthArray[j])
                        {
                            cell.Controls.Clear();
                            cell.Controls.Add(new LiteralControl("<a href='#?tid=" + day.Date.Year.ToString() + day.Date.Month.ToString() + day.Date.Day.ToString() + "' style='color:red;text-decoration:underline' target='_self' >" + day.Date.Day.ToString() + "</a>"));
                        }
                        j++;
                    }

                }

            }

            protected void test_PreRender(object sender, EventArgs e)
            {
                Thread t = Thread.CurrentThread;
                System.Globalization.CultureInfo c = (System.Globalization.CultureInfo)t.CurrentCulture.Clone();
                c.DateTimeFormat.DayNames = new string[] { "日", "一", "二", "三", "四", "五", "六" };
                c.DateTimeFormat.FirstDayOfWeek = DayOfWeek.Monday;
                t.CurrentCulture = c;
            }

  • 相关阅读:
    @try { } @catch (NSException *exception) {} @finally {}
    键盘点出来就退不掉了,你可以把这几句加到有键盘的控制器里
    测试最新的微信iOS SDK 报错误
    堆、栈知识小结
    PV操作
    continue & break
    dll的def文件与__declspec(dllexport)导出函数方式比较
    setupapi.h和setupapi.lib該如何使用
    批量缺少头文件的解决办法(添加包含目录)
    易犯错误总结:
  • 原文地址:https://www.cnblogs.com/wlwjc/p/1793259.html
Copyright © 2011-2022 走看看