I'm invoking in the ItemDataBound event of repeater control an object that uses the value of the user's session, but I get error, it seems that the object can not to be created and when I use this same object in subsequent events at load, I haven't problem, I need to know when to start the session's variables at exist?.
the code is the follow:
protected void repDias_OnItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
DateTime date = (DateTime)e.Item.DataItem;
Literal litDia = (Literal)e.Item.FindControl("litDia");
HtmlTableCell tdDia = (HtmlTableCell)e.Item.FindControl("tdDia");
int vencidos=0;
int mantenimientos = 0;
string usuarioid;
string clienteid;
if (Session["Usuarioid"] != null)
usuarioid = Session["Usuarioid"].ToString();
if (Session["clienteid"] != null)
clienteid = Session["clienteid"].ToString();
lstFechaMantenimiento.DataSource = _m.obtenerTodos("", "",usuarioid, "", clienteid);
lstFechaMantenimiento.DataTextField = "sigrev";
lstFechaMantenimiento.DataValueField = "id";
lstFechaMantenimiento.DataBind();
DateTime dt= new DateTime();
DateTime dthoy = new DateTime();
DateTime dtfecha = new DateTime();
dt=DateTime.Now;
string hoy = string.Format("{2}-{1}-{0}", dt.Year, dt.Month.ToString("D2"), dt.Day.ToString("D2"));
dthoy = Convert.ToDateTime(hoy);
if (date.DayOfWeek == DayOfWeek.Saturday || date.DayOfWeek == DayOfWeek.Sunday)
tdDia.Attributes.Add("class", "weekend");
if (_actualMes == date.Month)
{
litDia.Text = string.Format("<a href=\"{0}?CalDate={3}-{2}-{1}\"{4}>{3}</a>", Request.Path, date.Year, date.Month.ToString("D2"), date.Day.ToString("D2"), (_specialDaySelected && date.Equals(_selectedDate)) ? " class=\"selected\"" : string.Empty);
fechamantenimiento = string.Format("{2}-{1}-{0}", date.Year, date.Month.ToString("D2"), date.Day.ToString("D2"));
dtfecha = Convert.ToDateTime(fechamantenimiento);
for (int i = 0; i < lstFechaMantenimiento.Items.Count; i++)
{
if (dthoy <= dtfecha)
{
if (fechamantenimiento == lstFechaMantenimiento.Items[i].Text)
{ mantenimientos = mantenimientos + 1; }
}
else
{
if (fechamantenimiento == lstFechaMantenimiento.Items[i].Text)
{ vencidos = vencidos + 1; }
}
}
if (mantenimientos > 0)
tdDia.Attributes.Add("class", "fechamantenimiento");
if (vencidos > 0)
tdDia.Attributes.Add("class", "vencido");
}
else
litDia.Text = string.Format("<span>{0}</span>", date.Day.ToString("D2"));
tdDia.ID = string.Empty;
}
}
Please, someone could help me.
thans in advance.