Calendar Control)

Source: Internet
Author: User

Calendar Control)
Customize the style and appearance for the calendar
Control the calendar selection mode
Set and obtain the selected date
Let the special date have a prompt. At the same time, we imitate the blog garden calendar and navigate toArticleTo
The calendar event dayrender is triggered when a day is presented.

Protected   Void Page_init ( Object Sender, eventargs E)
{ // Run only once
Arr =   New   String [ 13 ] [];
  For ( Int I = 0 ; I < 13 ; I ++ )
{
Arr [I] =   New   String [ 32 ];
}
Arr [ 1 ] [ 1 ] =   " New Year's Day " ;
Arr [ 2 ] [ 14 ] =   " Valentine's Day " ;
Arr [ 3 ] [ 8 ] =   " Women's Day " ;

// Fill in the drop-down menu of year, month, and day
  For ( Int Y =   1980 ; Y <   2050 ; Y ++ )
{
Ye. Items. Add (Y. tostring ());
}
  For ( Int M =   1 ; M <   13 ; M ++ )
{
Mo. Items. Add (M. tostring ());
}
  For ( Int D =   1 ; D <   32 ; D ++ )
{ // There is a problem. There is no 31st on July 31 !! Improvements required
Da. Items. Add (D. tostring ());
}
}

Protected   Void Dropdownlist1_selectedindexchanged ( Object Sender, eventargs E)
{
  Switch (Dropdownlist1.selectedvalue)
{
Case   " None " :
Calendar1.selectionmode = Calendarselectionmode. None;
Break ;
Case   " Dayweekmonth " :
Calendar1.selectionmode = Calendarselectionmode. dayweekmonth;
Break ;
Case   " Dayweek " :
Calendar1.selectionmode = Calendarselectionmode. dayweek;
Break ;
Case   " Day " :
Calendar1.selectionmode = Calendarselectionmode. Day;
Break ;
}
}

Protected VoidCalendar1_selectionchanged (ObjectSender, eventargs E)
{
Label1.text=Calendar1.selecteddate. tow.datestring ();
Label2.text=Calendar1.selecteddate. Day. tostring ();
Label3.text=Calendar1.selecteddate. Month. tostring ();
Label4.text=Calendar1.selecteddate. year. tostring ();
}

Protected   Void Button#click ( Object Sender, eventargs E)
{
  String Y = Ye. selectedvalue. tostring ();
  String M = Mo. selectedvalue. tostring ();
  String D = Da. selectedvalue. tostring ();
Calendar1.visibledate = Convert. todatetime (Y +   " - "   + M +   " - "   + D );
}

Protected   Static Datatable DS ( String Day) // Using system. Data. sqlclient;
{
Sqlconnection con =   New Sqlconnection (configurationmanager. connectionstrings [ " Pconn " ]. Connectionstring );
Sqldataadapter SDA =   New Sqldataadapter ();
SDA. selectcommand =   New Sqlcommand ( " Select [title_id], [pubdate], [title] from [titles] Where ([pubdate] =' "   + Day +   " ') " );
Dataset DS =   New Dataset ();
SDA. Fill (DS, " Titles " );
  Return DS. Tables [ " Titles " ];
}

Protected   Void Calendar#dayrender ( Object Sender, dayrendereventargs E) // Note that the event name is dayrender.
{
Calendarday d = E. Day; // Set current date
Tablecell C = E. cell; // Set current table
  If (D. isothermonth)
{ // If it is another month, the original holiday will be cleared.
C. Controls. Clear ();
}
  Else
{
Try
{
String Txt = Arr [D. Date. month] [D. Date. Day]; // Get the complete current [month] [Day]
If (Txt ! =   String . Empty)
{
String Day = E. Day. Date. tow.datestring (); // Get the current date and convert it to the short Date Format
Foreach (Datarow Dr In DS (day). Rows) // Each row in the cyclic Data View
{
C. Controls. Clear (); // First, we need to clear all elements in the table.
C. Controls. Add ( New Listeralcontrol ( " <A href = 'HTTP: // aidd2008.cnblogs.com /? Dt = "   + Day +   " '> <B> "   + E. Day. Date. Day +   " </B> </a> " ));
}

C. controls. add ( New literalcontrol ( "
" + txt )); // If yes, it is displayed after the date number.
}< BR >}< br> catch (exception exe)
{< br> response. write (exe. tostring ();
}< BR >}< br>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.