Search This Blog

Friday, November 30, 2012

Calendar show with different color of date depends on database value in c#



         

Calendar show with different color of date depends on database value.

  #region DayRender
   protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        {
            if (!e.Day.IsOtherMonth)
            {
                int Fmonth = e.Day.Date.Month;
                string Enroll = "123abcd";
                string sql = "select * from Atendence where Amonth=" + Fmonth + " and EnrollNo='" + Enroll.ToString() + "'";
                SqlDataReader dr = dut.ExecuteReader(sql);
                if (dr.Read())
                {
                    int i;
                    for (i = 1; i <= 31; i++)
                    {
                        if (e.Day.Date.Day == i)
                        {
                            if (dr["D" + i].ToString() == "1")
                            {
                                e.Cell.BackColor = Color.Green;
                            }
                            else if (dr["D" + i].ToString() == "0")
                            {
                                e.Cell.BackColor = Color.Red;
                            }
                            else if (dr["D" + i].ToString() == "2")
                            {
                                e.Cell.BackColor = Color.Yellow;
                            }
                            else
                            {
                                e.Cell.BackColor = Color.White;
                            }
                        }
                    }
                }

            }
            else

    { e.Cell.Text = ""; }

No comments :