Display selected dates from database to ASP.NET calender control ,Stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Anu Rose George

    Display selected dates from database to ASP.NET calender control ,Stored Procedure

    This is to help developers to display the selected dates from a table to calender control using DayRender event of Calender control

    Steps
    1.Create a table containing following fields
    Code:
       LID varchar(50)
       date datetime
    2. write a stored procedure to select dates from database
    corresponding to a specific user ID as follows
    Code:
        CREATE  PROCEDURE DISPLAYSCHEDULE
    	@LID varchar(50)	
        AS
    	select date from PSSDocShed
    	where LID=@LID
    Please Note that here DISPLAYSCHEDULE is the procedure name
    and PSSDocShed is the table Name
    3.write the business layer function as follows
    Code:
       
        public static DataTable displayschedule(string id)
        {
    
                DbCommand cmd = GenericData.CreateCommand();
                cmd.CommandText = "DISPLAYSCHEDULE";
                cmd.Parameters.Add(new SqlParameter("@LID", id));
                return GenericData.ExecuteReader(cmd);
    
        }
    4.Now create a calender control in aspx page from its property window click DayRender Event and Write the following code
    Code:
         protected void Calendar1_DayRender  (objectsender,DayRenderEventArgs e)
           {
            string id = Request.Cookies["PSSuid"].Value;
            DataTable tb = businessclass.displayschedule(id);
            for (int i = 0; i < tb.Rows.Count; i++)
            {
                
                if (e.Day.Date == Convert.ToDateTime(tb.Rows[i][0]))
                {
                    e.Cell.BackColor = System.Drawing.Color.Pink;
                   
                }
                
            }
            
        }
    Here the business class is included in the namespace LID is passed as id which is retrieved by cookie value now the dates from database are displayed in Pink color.
    Last edited by Frinavale; Oct 4 '10, 01:26 PM. Reason: Added code tags and fixed a couple of spelling errors.
Working...