How to Use Calender Control in Asp.Net C#

Calender Control


The Calendar control is used to display a calendar in the browser.


The calendar control is a functionally rich web control, which provides the following capabilities:


Displaying one month at a time

Selecting a day, a week or a month

Selecting a range of days

Moving from month to month

Controlling the display of the days programmatically                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 This control displays a one-month calendar that allows the user to select dates and move to the next and previous months.


PropertiesDescription
DayTo select a single day
DayWeekTo select a single day or an entire week
DayWeekMonthTo select a single day, a week or an entire month
NoneNothing can be selected


This control exists within 

System.Web.UI.WebControls namespace.



PropertiesDescription
CaptionGets or sets the caption for the calendar control.
CaptionAlignGets or sets the alignment for the caption.
CellPaddingGets or sets the number of space between the data and the cell.s border.
CellSpacingGets or sets the space between cells.
DayHeaderStyleGets the style properties for the section that displays the day of the week.
DayNameFormatGets or sets format of days of the week.
DayStyleGets the style properties for the days in the displayed month.
FirstDayOfWeekGets or sets the day of week to display in the first column.
NextMonthTextGets or sets the text for next month navigation control; default value is >
NextPrevFormatGets or sets the format of the next and previous month navigation control.
OtherMonthDayStyleGets the style properties for the days on the Calendar control that are not in the displayed month.
PrevMonthTextGets or sets the text for previous month navigation control; default value is <
SelectedDateGets or sets the selected date.
SelectedDatesGets a collection of DateTime objects representing the selected dates.
SelectedDayStyleGets the style properties for the selected dates.
SelectionModeGets or sets the selection mode that specifies whether the user can select a single day, a week or an entire month.
SelectMonthTextGets or sets the text for the month selection element in the selector column.
SelectorStyleGets the style properties for the week and month selector column.
SelectWeekTextGets or sets the text displayed for the week selection element in the selector column.
ShowDayHeaderGets or sets the value indicating whether the heading for the days of the week is displayed.
ShowGridLinesGets or sets the value indicating whether the gridlines would be shown.
ShowNextPrevMonthGets or sets a value indicating whether next and previous month navigation elements are shown in the title section.
ShowTitleGets or sets a value indicating whether the title section is displayed.
TitleFormatGets or sets the format for the title section.
TitlestyleGet the style properties of the title heading for the Calendar control.
TodayDayStyleGets the style properties for today's date on the Calendar control.
TodaysDateGets or sets the value for today.s date.
UseAccessibleHeaderGets or sets a value that indicates whether to render the table header <th> HTML element for the day headers instead of the table data <td> HTML element.
VisibleDateGets or sets the date that specifies the month to display.
WeekendDayStyleGets the style properties for the weekend dates on the Calendar control.


EventsDescription
SelectionChangedIt is raised when a day, a week or an entire month is selected
DayRenderIt is raised when each data cell of the calendar control is rendered.
VisibleMonthChangedIt is raised when user changes a month





Html Coding


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

             OnSelectionChanged="Calendar1_SelectionChanged"></asp:Calendar>
      
        <asp:TextBox ID="TextBox1" runat="server"

             Height="26px" Width="248px"></asp:TextBox>
       
   
    </div>
    </form>
</body>
</html>

C# Coding for LongDate


 protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox1.Text = Calendar1.SelectedDate.ToLongDateString();
    }


C# Coding for ShortDate


 protected void Calendar1_SelectionChanged(object sender, EventArgs e)
    {
        TextBox1.Text = Calendar1.SelectedDate.ToShortDateString();

    }




First - Add - new WebForm -  Select Calender Control From Toolbox








Next  - Select  -  textbox Select  from Dispaly the Date 












Next - Double Click the Calender Control  









Go to - Coding Page write coding for Select  Calender Date






Next - F5 - Run the Program

Select  One Date  Display  Full date ,month,year






Go to - Coding Page Write Coding for Select  Calender Date






Next - F5 - Run the Program

Select - One Date  Display  mm/dd/yyyy






0 comments:

Post a Comment