【问题标题】:How to highlight specific days in a calendar control ASP.net?如何突出显示日历控件 ASP.net 中的特定日期?
【发布时间】:2019-03-11 21:58:26
【问题描述】:

我正在尝试创建一个日历,突出显示在DropDownList1 中选择的大厅中发生活动的日期。

public partial class Calendar : System.Web.UI.Page
{
    IQueryable<Activity> activities;

    protected void Page_Init(object sender, EventArgs e)
    {
        int idHall;
        bool b = Int32.TryParse(DropDownList1.SelectedValue, out idHall);
        if (!b)
        {
            idHall = 2;
        }

        ModelDatabase db = new ModelDatabase();

        activities = from a in db.Activities
                     join s in db.Halls on a.hall_id_hall equals s.id_hall
                     where s.i[d_hall == idHall
                     select a;][1]
    }

    protected void Page_Load(object sender, EventArgs e)
    {


    }

    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        foreach (Activity a in activities) {
            DateTime calendarDay = e.Day.Date;
            DateTime activityStart= a.start ?? default(DateTime);
            DateTime activityEnd = a.end ?? default(DateTime);
            if (DateTime.Compare(activityStart, calendarDay) > 0 && 
                DateTime.Compare(activityEnd, calendarDay.AddDays(1)) < 0)
            {
                e.Cell.BackColor = Color.Yellow;
                break;
            }
        }
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {
        int idSalon = Int32.Parse(DropDownList1.SelectedValue);

        ModelDatabase db = new ModelDatabase();

        activities = from a in db.Activities
                     join h in db.Halls on a.hall_id_hall equals h.id_hall
                     where h.id_hall == idHall
                     select a;
    }

【问题讨论】:

    标签: c# asp.net linq webforms


    【解决方案1】:

    在我写问题的时候解决了。 我所要做的就是将Page_Init 中的代码移动到Page_load。 阅读ASP.NET Page Life Cycle 帮助了我。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多