Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,450 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 2,081 people online right now. Registration is fast and FREE... Join Now!




C# calendar

 
Reply to this topicStart new topic

C# calendar

Trake
12 Aug, 2008 - 02:27 AM
Post #1

D.I.C Head
**

Joined: 29 Jun, 2007
Posts: 60


My Contributions
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>&nbsp;</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);
}
}
}

User is offlineProfile CardPM
+Quote Post

PsychoCoder
RE: C# Calendar
12 Aug, 2008 - 07:50 AM
Post #2

using DIC.Core;
Group Icon

Joined: 26 Jul, 2007
Posts: 8,993



Thanked: 125 times
Dream Kudos: 8625
Expert In: VB, VB.Net, C#, SQL, ASP, ASP.Net, Web Development, HTML, CSS, Win32 API, Javascript, mySQL, J#, Boo.Net

My Contributions
Moved to the ASP.NET Forum smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 03:00PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month