我正在尝试创建一个日历,以突出显示在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;
}
答案 0 :(得分:0)
解决了我在写问题时的问题。
我所要做的就是将Page_Init
中的代码移动到Page_load
中。
读ASP.NET Page Life Cycle对我有帮助。