Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have got one list with 5 sort of items:

Kontrakt | Pracownik | Dzien | ID | Procenty

And When i Have 1000 elements its render me very slow on calendar. About 5-6 secounds. How can I do it fdaster and analyse them. Can I put the indexer on column ?

I have got that code to render on Calendar:

  protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        e.Cell.VerticalAlign = VerticalAlign.Top;
        SPWeb witryna = SPContext.Current.Web;
        SPListItemCollection listaDniPrzeznaczonychNaProjekt = witryna.Lists["Szczegoly"].Items;

            // Gdy nie ma zaznaczonej osoby to wtedy wyświetlamy wszystkie daty urlopów

            int index;

            if (DropDownList1.SelectedItem.Text == "<-- Wszystcy pracownicy -->" || DropDownList1.SelectedItem.Text == "")
            {

                foreach (SPListItem olistaDniPrzeznaczonychNaProjekt in listaDniPrzeznaczonychNaProjekt)
                {

                    if (e.Day.Date.Date.ToShortDateString() == Convert.ToDateTime(olistaDniPrzeznaczonychNaProjekt["Dzien"]).ToShortDateString())
                    {
                        e.Cell.Style.Add("background-color", "#FF0000");
                        e.Cell.CssClass = "dni_swiateczne";
                    }

                }
            }
            else

            // Renderowanie urlopu dla pojedyńczej zaznaczonej osobie
            {
                foreach (SPListItem olistaDniPrzeznaczonychNaProjekt in listaDniPrzeznaczonychNaProjekt)
                {
                    index = olistaDniPrzeznaczonychNaProjekt["Pracownik"].ToString().IndexOf("#");

                    if (DropDownList1.SelectedItem.Text == olistaDniPrzeznaczonychNaProjekt["Pracownik"].ToString().Substring(index + 1))
                    {
                        if (e.Day.Date.Date.ToShortDateString() == Convert.ToDateTime(olistaDniPrzeznaczonychNaProjekt["Dzien"]).ToShortDateString())
                        {
                            e.Cell.Style.Add("background-color", "#F5BCA9");
                            e.Cell.CssClass = "dni_swiateczne";
                            e.Cell.Controls.Add(new LiteralControl(("<p style='color:blue; font-size:8px;'>" + olistaDniPrzeznaczonychNaProjekt["Kontrakt"].ToString() + "</p><p style='color:#5D198E;'>" + olistaDniPrzeznaczonychNaProjekt["Procenty"].ToString().Substring(3) + "</p>")));
                        }

                    }

                }

            }
            SPWeb witryna1 = SPContext.Current.Web;
            SPListItemCollection listaDniSwiatecznych = witryna1.Lists["DR2013 Święta"].Items;

            foreach (SPListItem olistaDniSwiatecznych in listaDniSwiatecznych)
            {
                // Wyświetlenie na kalendarzu weekendów
                if (e.Day.Date.Date.DayOfWeek.ToString() == "Saturday" || e.Day.Date.Date.DayOfWeek.ToString() == "Sunday")
                {
                    e.Cell.Style.Add("background-color", "#FF9900");
                    e.Cell.CssClass = "dni_swiateczne";
                }

                // Wyświetlenie na kalendarzu dni świątecznych
                if (e.Day.Date.Date.ToShortDateString() == Convert.ToDateTime(olistaDniSwiatecznych["Data"]).ToShortDateString())
                {
                    e.Cell.Style.Add("background-color", "#FFFF00");
                    e.Cell.CssClass = "dni_swiateczne";
                    e.Cell.Controls.Add(new LiteralControl(("<p style='color:red; font-size:8px;'>" + olistaDniSwiatecznych["Data"].ToString().Substring(0, 10) + "</p>")));
                }

            }
    } // Koniec protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
share|improve this question

1 Answer 1

up vote 1 down vote accepted

Use SPQuery to query your data instead of looping through all of it.

I'd recommend that you watch the videos at mssharepointdeveloper.com before starting to develop for SharePoint. Module 4 "Accessing SharePoint 2010 data and objects with server-side APIs" will give you some information about how to access data.

share|improve this answer
    
Thanks, for fast replay :) But i must use a calm ? –  Grzegorz Z Oct 19 '12 at 12:24
1  
Yes you should use CAML and unless you need to render all of the data it'll be faster. Currently you're doing something similar to an SQL query like SELECT * FROM list where with the right CAML it'll be like SELECT Kontract, Procenty FROM list WHERE Dzien=selecteddate AND Pracownik=selecteditem –  Per Jakobsen Oct 19 '12 at 12:38
1  
In most cases LINQ will generate fine CAML, but sometimes it'll create something as bad as the SELECT * from list. –  Per Jakobsen Oct 19 '12 at 13:03
1  
U2U CAML Query Builder is an excellent tool to use –  Per Jakobsen Oct 19 '12 at 14:44
1  
No!!! First off it's wrong as it'll only work if all days in your calendar is within 11 days of today. Second your query should be narrow enough to eliminate all if statements inside your foreach loops. But let that discusion continue in your new question –  Per Jakobsen Oct 20 '12 at 20:59

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.