How to Use the calendar Control for calendar management

Source: Internet
Author: User

A few days ago, the lead gave me a task: to write a calendar management function.
I have never written such a function before and have no idea when receiving tasks.
Finally, I found some information on the Internet, but I didn't find any good information. I only found the information that can be implemented using the calendar control.

Finally, it took me a few days to write the calendar management function. Now I will share it with you and hope you will give me more advice.
1. I want to talk about the dayrender event mainly using the calendar control.
/// <Summary>
/// Read the calendar information and set the calendar
/// Zhou haijun
/// </Summary>
/// <Param name = "sender"> </param>
/// <Param name = "E"> </param>
Protected void calschedule_dayrender (Object sender, dayrendereventargs E)
{
// Custom display content
// Obtain the date that is displayed in the calendar control.
Calendarday d = (dayrendereventargs) e). Day;
Calendarday day = E. Day;
// Obtain the cell that is displayed in the calendar control.
Tablecell c = (dayrendereventargs) e). cell;
// C. width = 230;
// Create a lunar conversion class
// Lunar LR = new lunar ();
If (D. isothermonth)
{
C. Controls. Clear ();
}
Else
{
Datetime fdate = new datetime ();
String subject;
Datetime date = new datetime ();
Date = D. date;
Try
{
C. Controls. Clear ();
// Display the date of the current day and the hyperlink
C. Controls. Add (New literalcontrol ("<a href = 'schedbyday. aspx? Date = "+ D. date. year. tostring () + "-" + D. date. month. tostring () + "-" + D. date. day. tostring () + "'style = 'color: #003080; font-size: 12px; '>" + D. date. day. tostring () + "</a> "));
C. controls. add (New literalcontrol ("& nbsp;" + "& nbsp; "+" & nbsp; "+" & nbsp ;"));

// Display hyperlinks, customize a hyperlink, and set attributes
Hyperlink ahyperlink = new hyperlink ();
Ahyperlink. imageurl = "../images/add_small.gif ";
Ahyperlink. tooltip = "add personal calendar ";
Ahyperlink. navigateurl = "plan_addedit.aspx? Id = add & date = "+ D. date. year. tostring () + "-" + D. date. month. tostring () + "-" + D. date. day. tostring () + "";
//
C. Controls. Add (ahyperlink );


}
Catch (exception exc)
{
Response. Write (EXC. tostring ());
}
// Read the information of the day

Plan_day = new plan_day ();
Datatable dt = plan_dayinfo.plan_getby_dateanduser (date. tostring ("yyyy-mm-dd"), inuser );

// Display all information for the day
Try
{
If (DT! = NULL)
{
For (INT I = 0; I <DT. Rows. Count; I ++)
{
// Obtain the calendar primary key planid
Int planid = int32.parse (Dt. Rows [I] ["plan_id"]. tostring ());
// Get the calendar date
Fdate = datetime. parse (Dt. Rows [I] ["plan_date"]. tostring ());
// Only obtain the hour and minute
String fdate_hour = fdate. Hour. tostring ();
String fdate_minute = fdate. Minute. tostring ();
If (fdate_minute = "0 ")
{
Fdate_minute = "00 ";
}
// Obtain the calendar title
Subject = DT. Rows [I] ["plan_subject"]. tostring ();
// Only take the first four digits of the title
If (subject. length> 4)
{
Subject = subject. substring (0, 4 );
Subject + = "..";
}
Htmlanchor A = new htmlanchor ();
// Detailed information pointing to the calendar
A. href = "plan_addedit.aspx? Id = "+ planid + "";
A. innertext ="☉"+ Subject + "";
A. Attributes. Add ("style", "font-size: 12px ;");
C. Controls. Add (New literalcontrol ("& nbsp;" + "& nbsp ;"));
C. Controls. Add (New literalcontrol ("<br> "));
C. Controls. Add ();

}
E. Cell. attributes ["onmouseout"] = "javascript: This. style. backgroundcolor = '';";
E. Cell. attributes ["onmouseover"] = "javascript: This. style. backgroundcolor = '# e8e8e8 ';";
}
}
Catch
{
Return;
}
}
}

Now Code It is also provided to you: I hope you can download the source code with more comments.

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.