Monday, 2 April 2018

018 Asp.net Calender

Calendar Control 
Calendar Control display one month calendar at a time, it is very popular Asp.Net server control to display calendar. This server control  is a Programmable. You can select next or previous date, month, year  by clicking on calendar control. Range of calendar control is 0 AD to 9999AD.


Here is some most popular attribute of the column calendar control.

 
Type Name Description
Constructor Calendar  New instance of the calendar control is created,
Property BackColor  Get or Set background color of the calendar control,
Property BorderColor  Get or Set border color of the calendar control.
Property BorderWidth  Get or Set border with of the calendar control.
Property CellPadding  Get or Set amount of space between data and cell  border.
Property CellSpacing  Get or Set amount of space between two cells.
Property ClientID  Get control ID in HTML which is generated from server to identify this control in HTML.
Property CssClass  Get or Set CSS of the control.
Property Enabled  Get or Set enabled the control or disabled the control.
Property ForeColor  Get or Set fore color of the control.
Property SelectedDate  Get or Set selected date.
Method Databind()  Bind data with the data source.
Method Dispose()  Dispose the calender control and release all the memories.
Method FindControl()  Search for a server control with parameter to identify the control.
Event Onload()  Raise an event when the control is load.
Event SelectionChanged()  Raise an event when change of selection on date ,month ,year.
Event VisibleMonthChanged()  Raise an event when when month is changed.

 Below are  example of calendar control usage

1) Populate calendar control with selected date. 

Default.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %>
<%@ OutputCache Duration="60" VaryByParam="DropDownList1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
         </head>
             <body>
                           <form id="form1" runat="server">
                                <div>
                                    <asp:Calendar ID="Calendar1" runat="server"></asp:Calendar>
                                </div>
                           </form>
             </body>
</html>

Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
               protected void Page_Load(object sender, EventArgs e)
               {
                     Calendar1.SelectedDate = new DateTime(208,12, 12);
                }
}

Output


2) Populate calendar control with stylesheet. 

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %>
<%@ OutputCache Duration="60" VaryByParam="DropDownList1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<style>
.xCalendar 
{
       background-color: #f2f2f2;
       width: 156px;
       border:10px solid #4CCAEF !important;
       border-top:0px !important;
}
.xCalendar a 
{
     text-decoration: none
}
.xCalendar .xCalendarTitle 
{
     font-weight: bold;
     height:40px;line-height:40px;
     background-color:#4CCAEF;
     color:#ffffff;
}
.xCalendar th.xCalendarDayHeader
{
     height:25px;
     border-bottom: outset 2px #fbfbfb;
     border-right: outset 2px #fbfbfb;
}
.xCalendar td.xCalendarDay 
{
     border: outset 2px #fbfbfb;
}
</style>

<body>
<form id="form1" runat="server">
        <div>
                   <asp:Calendar ID="Calendar1" runat="server" CssClass="xCalendar">
                           <OtherMonthDayStyle ForeColor="#b0b0b0" />
                           <DayStyle CssClass="xCalendarDay" ForeColor="#2d3338" />
                           <DayHeaderStyle CssClass="xCalendarDayHeader" ForeColor="#2d3338" />
                 <SelectedDayStyle Font-Bold="True" Font-Size="12px" CssClass="xCalendarSelector" />
                   </asp:Calendar>
        </div>
</form>
</body>
</html>

Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
          protected void Page_Load(object sender, EventArgs e)
         {
                 Calendar1.SelectedDate = new DateTime(208,12, 12);
         }
}

Output

3) Calendar event

Default.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" EnableViewState="false" %>
<%@ OutputCache Duration="60" VaryByParam="DropDownList1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
             <title></title>
        </head>
        <body>
                  <form id="form1" runat="server">
                     <div>
                              <asp:Calendar ID="Calendar1" runat="server"
                                  onselectionchanged="Calendar1_SelectionChanged"></asp:Calendar>
                     </div>
                     </form>
         </body>
</html>

Default.aspx.cs
using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
         protected void Page_Load(object sender, EventArgs e)
          {
               Calendar1.SelectedDate = new DateTime(208,12, 12);
           }

         protected void Calendar1_SelectionChanged(object sender, EventArgs e)
         {
               Response.Write("");
         }
}







Output


No comments:

Post a Comment

বাঙালির বেড়ানো সেরা চারটি ঠিকানা

  বাঙালি মানে ঘোড়া পাগল | দু একদিন ছুটি পেলো মানে বাঙালি চলল ঘুরতে | সে সমুদ্রই হোক , পাহাড়ি হোক বা নদী হোক। বাঙালির ...