protected void Calendar_program_SelectionChanged(object sender, EventArgs e)
        {
            DateTime dt = Calendar_program.SelectedDate;
            while (dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);

            Label_program_dag.Text = dt.ToShortDateString() + " - ";
            Label_program_sidste_dag.Text = dt.AddDays(6).ToShortDateString();
            Repeater_program_dag.DataSource = program_dag(dt, dt.AddDays(6));
            Repeater_program_dag.DataBind();
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            DateTime dt = DateTime.Now;
            while(dt.DayOfWeek != DayOfWeek.Monday) dt = dt.AddDays(-1);

            Conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
            Label_program_dag.Text = dt.ToShortDateString() + " - ";
            Label_program_sidste_dag.Text = dt.AddDays(6).ToShortDateString();

            Repeater_program_dag.DataSource = program_dag(dt, dt.AddDays(6));
            Repeater_program_dag.DataBind();
            Calendar_program.SelectionMode = CalendarSelectionMode.DayWeek;
        }
Ejemplo n.º 3
0
        private void cbMonth_SelectedIndexChanged(object sender, EventArgs e)
        {
            int month = (cbMonth.SelectedItem as ComboboxItem).Value.ToInt();
            if (cbMonth.SelectedIndex != 0)
            {

                startDate = new DateTime(startDate.Year, month, 1, 1, 0, 0, 0);
                endDate = new DateTime(endDate.Year, month, DateTime.DaysInMonth(endDate.Year, month), 23, 59, 59);

                DateTimeFormatInfo dfi = DateTimeFormatInfo.CurrentInfo;
                Calendar cal = dfi.Calendar;

                if (startDate.DayOfWeek != DayOfWeek.Monday) { startDate = startDate.AddDays(7); }
                DateTime dt = startDate;

                if (cbWeek.Items.Count == 0)
                {

                    cbWeek.Items.Add(new ComboboxItem { Text = "กรุณาเลือกสัปดาห์...", Value = 0 });

                    DayOfWeek startOfWeek = DayOfWeek.Monday;

                    int diff = dt.DayOfWeek - startOfWeek;
                    if (diff < 0)
                    {
                        diff += 7;
                    }
                    dt = dt.AddDays(-1 * diff).Date;

                    for (int i = 1; i <= 4; i++)
                    {
                        cbWeek.Items.Add(new ComboboxItem { Text = "ตั้งแต่ " + dt.ToShortDateString() + " ถึง " + dt.AddDays(6).ToShortDateString() , Value = dt.Day });
                        dt = dt.AddDays(7);
                    }

                    cbWeek.SelectedIndex = 0;
                }
                else
                {
                    cbWeek.Items.Clear();
                    cbWeek.Items.Add(new ComboboxItem { Text = "กรุณาเลือกสัปดาห์...", Value = 0 });
                    DayOfWeek startOfWeek = DayOfWeek.Monday;
                    int diff = dt.DayOfWeek - startOfWeek;
                    if (diff < 0)
                    {
                        diff += 7;
                    }
                    dt = dt.AddDays(-1 * diff).Date;
                    for (int i = 1; i <= 4; i++)
                    {
                        cbWeek.Items.Add(new ComboboxItem { Text = "ตั้งแต่ " + dt.ToShortDateString() + " ถึง " + dt.AddDays(6).ToShortDateString(), Value = dt.Day });
                        dt = dt.AddDays(7);
                    }
                    cbWeek.SelectedIndex = 0;
                }
            }
        }