简体   繁体   English

高效地填充ASP.Net日历控件

[英]Efficiently populating an ASP.Net Calendar control

I have an ASP.Net Calendar control that, on DayRender, loops through a list of "CalendarEvents" (one of my classes). 我有一个ASP.Net日历控件,该控件在DayRender上循环遍历“ CalendarEvents”列表(我的一个类)。 If the day that DayRender is on is in the list of CalendarEvents, then fill that calendar cell with the details of the event. 如果DayRender的启用日期在CalendarEvents列表中,则用事件的详细信息填充该日历单元格。

In my test environment, there is no problem, but I imagine with thousands of records, it might become a problem. 在我的测试环境中,没有问题,但是我想象成千上万的记录可能会成为问题。 Here is what I'm doing: 这是我在做什么:

public partial class calendar : System.Web.UI.Page
{
    CalendarEventList allevents = CalendarEventManager.GetListAll();

    //Page_Load, etc...

    protected void calmaincalendar_DayRender(object sender, DayRenderEventArgs e)
    {
        foreach (CalendarEvent x in allevents)
        {
            if (e.Day.Date == x.EventDate)
            {
                //logic to extract the data from x, and modify the e.Cell to display that data
            }
        }
    }
}

My questions are: 我的问题是:

1) I'm putting the events as a page level variable, so that the database only needs to be called once, and not on every single DayRender. 1)我将事件作为页面级变量,这样数据库只需调用一次,而不是在每个DayRender上调用。 Good, bad? 好坏? Potential issues? 潜在的问题? This page is purely to read the Calendar Events, not edit or delete. 此页面仅用于阅读日历事件,而不是编辑或删除。

2) Looping through the "allevents" list on every DayRender, is that potentially dangerous/resource intensive? 2)遍历每个DayRender上的“ allevents”列表,这是否潜在危险/资源密集? Does the Calendar control call DayRender for just the month that's being displayed? 日历控件仅在显示的月份中调用DayRender吗? If so, meaning only 30 or 31 calls at a time, it might be fine. 如果是这样,则意味着一次仅拨打30或31个电话,可能就可以了。 But if it does something like calls DayRender for the entire year, or the previous and next months as well...Anyway, hopefully you get my point. 但是,如果它在整个年度或之前和接下来的几个月中都进行了类似DayRender的调用……无论如何,希望您能理解我的意思。 Advice on this would be appreciated. 对此的建议将不胜感激。

3) Is there anything that I could be doing better? 3)有什么我可以做得更好的吗? I realize I only posted the bare skeleton, but if anyone has any similar experience, or pitfalls they wished they had realized earlier, that advice would be appreciated. 我知道我只是发布了裸露的骨架,但是如果有人有任何类似的经历,或者他们希望早点意识到的陷阱,那么我们将不胜感激。


As I was typing up the questions I realized that when I get the CalendarEventList at the page level, I could immediately loop through it and cut out everything except for the last 3 and future 3 months or something. 当我输入问题时,我意识到,当我在页面级别获得CalendarEventList时,我可以立即遍历它并切出除最近3个月和以后3个月之类的所有内容。 Problem there is, somehow keeping track of it so that when the user goes back 4 months, I'd have to realize this and call the database again. 问题是,以某种方式对其进行跟踪,以便当用户返回四个月时,我必须意识到这一点并再次调用数据库。 I have a vague feeling that the answer is somewhere in that direction, but still not sure. 我有一个模糊的感觉,答案在那个方向上,但仍然不确定。

As you talk about records I guess you have an underlying database. 当您谈论记录时,我想您有一个基础数据库。 If so, I will suggest to create a query for that, so you can do this: 如果是这样,我建议为此创建一个查询,因此您可以执行以下操作:

foreach (CalendarEvent x in CalendarEventManager.GetForDate(e.Day.Date))
{
    //logic to extract the data from x, and modify the e.Cell to display that data
}

This way, you will retrieve just the needed records. 这样,您将只检索所需的记录。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM