Hi all,
I am trying to create a calendar web page where for each month the page displays a div for each day with the day number displayed in the div. So far I can get one month to display and I can go forward another month but then after that I can not go forward again. I have not tried with years or going back months yet but they are required also.
Any help is really appreciated.
Here is my code so far:
css
body {
background-color: #9AC3DA;
font-family: Arial;
color: #FFF;
margin: 0 auto;
width: 760px;
}
h1 {
font-size: 36px;
font-weight: bold;
margin: 10px 0 10px 10px;
}
.day {
width: 80px;
height: 80px;
border: 1px solid #000;
background-color: #0000FF;
font-size: 18px;
text-align: center;
margin: 10px;
float: left;
}
div:hover {
background-color: #EE55CC;
}HTML
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="preForm.aspx.cs" Inherits="preForm" %>
<!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>
<link rel="Stylesheet" type="text/css" href="StyleSheet.css" />
</head>
<body>
<form id="form1" runat="server">
<p> </p>
<p>
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="Next Month" />
</p>
</form>
</body>
</html>
csharp
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Text;
using System.Collections.Specialized;
using System.Drawing;
public partial class preForm : System.Web.UI.Page
{
int counter;
int startMonth = 10;
int startYear = 2008;
int month;
int year;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
counter = 1;
update(startMonth, startYear);
}
}
protected void update(int newMonth, int newYear)
{
int processMonth = newMonth - 1;
int processYear = newYear - 1;
DateTime dt = new DateTime();
DateTime dt2 = dt.Date.AddMonths(processMonth).AddYears(processYear);
string monthNow = dt2.ToString("MMMM");
int monthNowNumber = dt2.Month;
int yearNow = dt2.Year;
int monthDays = DateTime.DaysInMonth(yearNow, monthNowNumber);
Page.Title = monthNow + " " + yearNow;
Response.Write("<h1 id=\"headline\" runat=\"server\">" + monthNow + " " + yearNow + "</h1>");
for (int i = 1; i < (monthDays + 1); i++)
{
Response.Write("<div id=\"day" + i + "\" class=\"day\" runat=\"server\"><p>" + i + "</p></div>");
}
}
protected void Button1_Click(object sender, EventArgs e)
{
Response.Clear();
counter++;
if (counter >= 1)
{
month = startMonth + counter;
if (month >= 12)
{
year++;
}
else
{
year = startYear;
}
update(month, year);
}
}
}