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;
            }

  • 相关阅读:
    SpringBoot2.x整合JDBC及初始化data.sql和schema.sql脚本
    CentOS7安装docker以及错误解决
    Maven的scope属性作用域范围
    (转)排序算法之简单选择排序
    系统开发博客专栏
    IDEA启动报错Plugin Error Problems found loading plugins的解决办法
    Promise函数的使用
    (转)排序算法之希尔排序
    .net Core AJAX使用Header传递参数,以JsonResult返回信息
    MVC 扩展RadioButtonListFor和CheckBoxListFor
  • 原文地址:https://www.cnblogs.com/wlwjc/p/1793259.html
Copyright © 2011-2022 走看看