Search This Blog

Wednesday, October 27, 2010

Set color in calender cell.

using System;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Drawing;
public partial class Webadmin_Atendence_view : System.Web.UI.Page
{
    datautl dut = new datautl();
    protected void Page_Load(object sender, EventArgs e)
    {
      
    }
    protected void Calendar1_Load(object sender, EventArgs e)
    {
    }
    //***********************************day render create cell load time*************************************************************
    #region DayRender
    protected void Calendar1_DayRender(object sender, DayRenderEventArgs e)
    {
        if (!e.Day.IsOtherMonth)
        {
            //Response.Write(DateTime.Now.Month.ToString());
            int Fmonth = e.Day.Date.Month;
            string Enroll = "123abcd";
            string sql = "select * from Giip_Atendence where Amonth=" + Fmonth + " and EnrollNo='" + Enroll.ToString() + "'";
            SqlDataReader dr = dut.ExecuteReader(sql);
            //Convert.ToInt32(DateTime.Now.Month);
            //Response.Write(Fmonth);
            //Response.End();
            //Response.Write(Enroll);
            //Response.Write(sql);
            //dr.Read();
            //****************************dr.read returm true or false value*******************************************
            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 = ""; }
    }
    #endregion
}

No comments :