I am trying to learn CAML Queries. I must render a lot of data on Calendar. I made a code, but if it has got more then 1000 elements it's doing very long about 4-5 seconds. It's longer then adding to list 1000 elements. I made a CAML Query on U2U CAML Query Builder. This is my CAML Query:
<Query> <Where> <And> <Lt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today+30Day(s)]</Value> </Lt> <Gt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today-30Day(s)]</Value> </Gt> </And> </Where> </Query>
It's good enough to very faster my code ? I'm very new on CAML. Can I have indexes on CAML like in Data Base ?
Here is my render code before CAML:
`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)
` It's render after change month of Calendar about 4-5 secounds

<Query> <Where> <And> <Lt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today+30Day(s)]</Value> </Lt> <Gt> <FieldRef Name='Dzien' /> <Value Type='DateTime'>[Today-30Day(s)]</Value> </Gt> </And> </Where> </Query>– Grzegorz Z Oct 20 '12 at 7:35