winstalla
asked on
ASP.NET Calendar - add 4 years.
I have a page that is used to add records to a Database. I have 2 Calendars - one for the purchase date and one for the retirement date of the equipment, which is 4 years from the purchase date by default, but can be manually changed if required.
So, I have the page and the two calendars, but I can't figure out how to get Calendar2 to Display a date 4 years in the future. Even 4 years from "DateTime.Today" would be fine!
This kind of question has probably been asked before, but I can't seem to find it. Sorry!
So, I have the page and the two calendars, but I can't figure out how to get Calendar2 to Display a date 4 years in the future. Even 4 years from "DateTime.Today" would be fine!
<%@ Import Namespace="System.Data.Oledb" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
Protected Sub Page_Load()
If Page.IsPostBack = False Then
Label1.Visible = False
End If
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim Connection As New OleDbConnection("Provider=Microsoft.Jet.Oledb.4.0;" & _
"Data Source=E:\Company\New_Intranet\Guestbook2\App_Data\twit.mdb")
Connection.Open()
Dim Command As New OleDbCommand("INSERT INTO requests(Username, Forename, Make, Model, Serial, Acquired, Expires, Condition, Location, Comments" & _
")VALUES(@Username,@forename,@Make,@model,@Serial,@Acquired,@expires,@condition,@Comments,@location)", Connection)
Command.Parameters.Add(New OleDbParameter("@Username", TextBox1.Text))
Command.Parameters.Add(New OleDbParameter("@Forename", TextBox8.Text))
Command.Parameters.Add(New OleDbParameter("@make", TextBox2.Text))
Command.Parameters.Add(New OleDbParameter("@model", TextBox3.Text))
Command.Parameters.Add(New OleDbParameter("@serial", TextBox4.Text))
Command.Parameters.Add(New OleDbParameter("@acquired", Calendar1.SelectedDate))
Command.Parameters.Add(New OleDbParameter("@expires", Calendar2.SelectedDate))
Command.Parameters.Add(New OleDbParameter("@condition", DropDownList1.Text))
Command.Parameters.Add(New OleDbParameter("@location", DropDownList2.Text))
Command.Parameters.Add(New OleDbParameter("@comments", TextBox7.Text))
Command.ExecuteNonQuery()
Connection.Close()
Label1.Text = "The Selected Record has been inserted."
Label1.Visible = True
'Clear the text boxes after a new insert
TextBox1.Text = ""
TextBox2.Text = ""
TextBox3.Text = ""
TextBox4.Text = ""
TextBox7.Text = ""
TextBox8.Text = ""
End Sub
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id=Head1 runat="server"><link rel="shortcut icon" href="images/headers/favicon.ico">
<title>Form to Add New Hardware</title>
<link href="Styles/Site.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.style1
{
color: #FF0000;
}
.style2
{
width: 275px;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<table border="0" cellpadding="3" width="800"><tr><td align="center"><b>Surname</b>
<span class=style1>*</span></TD><TD align="center"><asp:TextBox ID="TextBox1" runat="server" Text=""></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" ControlToValidate="TextBox1" runat="server" ErrorMessage="Please enter a Surname. Enter UNKNOWN if no User assigned"></asp:RequiredFieldValidator></td></tr>
<tr><td align="center"><b>Forename</b> <span class=style1>*</span></TD><TD align="center"><asp:TextBox ID="TextBox8" runat="server" Text=""></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator7" ControlToValidate="TextBox8" runat="server" ErrorMessage="Please enter a Forename. Enter UNKNOWN if no User assigned"></asp:RequiredFieldValidator></td></tr>
<TR><td align="center"><b>Location</b> <span class="style1">*</span></td><td align="center">
<asp:DropDownList ID="DropDownList2" runat="server">
<asp:ListItem Selected="True">Bolton (1st)</asp:ListItem>
<asp:ListItem>Bolton (2nd)</asp:ListItem>
</asp:DropDownList></td></TR>
<tr><td align="center" class="style2"><B>Manufacturer</B> <span class="style1">*</span></TD><TD align="center"> <asp:TextBox ID="TextBox2" runat="server" Text=""></asp:TextBox></td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" ControlToValidate="TextBox2" runat="server" ErrorMessage="Please enter a Manufacturer. Enter UNKNOWN if no Manufacturer available."></asp:RequiredFieldValidator></td></tr>
<TR><td align="center"><B>Model</B> <span class="style1">*</span></td><td align="center"> <asp:TextBox ID="TextBox3" runat="server" Text=""></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator3" ControlToValidate="TextBox3" runat="server" ErrorMessage="Please enter a Model. Enter UNKNOWN if no Model Number available."></asp:RequiredFieldValidator></td></TR>
<TR><TD align="center"><b>Serial Number</b> <span class="style1">*</span></TD><td align="center"><asp:TextBox ID="TextBox4" runat="server" Text=""></asp:TextBox>
</td>
<td><asp:RequiredFieldValidator ID="RequiredFieldValidator4" ControlToValidate="TextBox4" runat="server" ErrorMessage="Please enter a Serial Number. Enter UNKNOWN if no Serial Number available."></asp:RequiredFieldValidator></td></TR>
<TR><TD align="center"><b>Acquired Date (d/m/yy)</b> <span class="style1">*</span></TD><td align="center">
<asp:Calendar ID="Calendar1" runat="server" BackColor="White"
BorderColor="#3366CC" BorderWidth="1px" CellPadding="1"
DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#003399" Height="150px" Width="150px" SelectedDate="<%# DateTime.Today %>">
<DayHeaderStyle BackColor="#99CCCC" ForeColor="#336666" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#003399" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
<TR><TD align="center"><b>Retirement Date (d/m/yy)</b> <span class="style1">*</span></TD><td align="center">
<asp:Calendar ID="Calendar2" runat="server" BackColor="White"
BorderColor="#3366CC" BorderWidth="1px" CellPadding="1"
DayNameFormat="Shortest" Font-Names="Verdana" Font-Size="8pt"
ForeColor="#003399" Height="150px" Width="150px">
<DayHeaderStyle BackColor="#FF6666" ForeColor="Maroon" Height="1px" />
<NextPrevStyle Font-Size="8pt" ForeColor="#CCCCFF" BackColor="#FF5050" />
<OtherMonthDayStyle ForeColor="#999999" />
<SelectedDayStyle BackColor="#009999" Font-Bold="True" ForeColor="#CCFF99" />
<SelectorStyle BackColor="#99CCCC" ForeColor="#336666" />
<TitleStyle BackColor="#FF5050" BorderColor="#3366CC" BorderWidth="1px"
Font-Bold="True" Font-Size="10pt" ForeColor="#CCCCFF" Height="25px" />
<TodayDayStyle BackColor="#99CCCC" ForeColor="White" />
<WeekendDayStyle BackColor="#CCCCFF" />
</asp:Calendar>
</td>
<TR><td align="center"><b>Condition</b> <span class="style1">*</span></td><td align="center">
<asp:DropDownList ID="DropDownList1" runat="server">
<asp:ListItem Selected="True">New/Near New</asp:ListItem>
<asp:ListItem>Good</asp:ListItem>
</asp:DropDownList></td></TR>
<TR><td align="center"><b>Comments</b></td><td align="center"> <asp:TextBox ID="TextBox7" runat="server" Text=""></asp:TextBox></td></TR>
</table>
<asp:Button ID=Button1 runat="server" Text="Insert Record" OnClick="Button1_Click" />
<br />
<asp:Label ID=Label1 runat="server" Text=""></asp:Label>
</form>
</div>
</body>
</html>
The code above has been modified to only include the bits I think are required for this question. If more code is needed, I can supply it.This kind of question has probably been asked before, but I can't seem to find it. Sorry!
Calender1.SelectedDate=Dat eTime.Toda y.AddYears (4);
I don't think
Calender1.SelectedDate=Dat eTime.Toda y.AddYears (4);
on its own will work. Try
Calender1.SelectedDate=Dat
on its own will work. Try
Calender1.SelectedDate=DateTime.Today.AddYears(4)
Calender1.VisibleDate=DateTime.Today.AddYears(4)
ASKER
Sorry for the daft question, but put the line(s) where, exactly?
Apologies - I'm still fudging(?) my way around ASP.NET. Trying to sprint before I can walk, I think...
Apologies - I'm still fudging(?) my way around ASP.NET. Trying to sprint before I can walk, I think...
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
set visible date with the selected date value.
selected date will only sets the date. but the visible date value will be displayed in browser
selected date will only sets the date. but the visible date value will be displayed in browser
Calendar1.SelectedDate = Date.Today
Calendar2.VisibleDate = CDate(Date.Today.AddDays(4))
Calendar2.SelectedDate = CDate(Date.Today.AddDays(4))
Test this
i delayed to submit. ;-) @BuggyCoder has fixed the issue.
ASKER
This is working. Thank you.