Wrox Programmer Forums
|
ASP.NET 1.0 and 1.1 Basics ASP.NET discussion for users new to coding in ASP.NET 1.0 or 1.1. NOT for the older "classic" ASP 3 or the newer ASP.NET 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.0 and 1.1 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 8th, 2003, 06:56 PM
Registered User
 
Join Date: Aug 2003
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Change selecteddate for Calendar

On page 507 of Beginning ASP.Net:

<asp:Calendar id="MyCalendar" runat="server"
SelectedDate="2003/08/05"

How can I change the hard-coded date in the sample to today's date? I've tried taking the selecteddate specification out, but then the sample uses a date of 1/1/0001 ("No Events Scheduled For Monday, January 01, 0001"), although the calendar displays today's date.

I've tried using variables to no avail (when declaring variables and assigning to calendar.selecteddate in page sub_load, says "calendar is not declared" and won't allow me to use code blocks within a server tag) Can anyone help? TIA!

BTW, here's a code snippet with the above in context...

[SCRIPT SECTION:]
Protected Sub ShowDailyEvents()
    Dim dataSet As DataSet = LoadMyCalendarData()
    If dataSet is Nothing then
        Exit Sub
    End If
    'bind to repeater control
    Dim eventsForToday As DataSet
    eventsForToday= GetEventsDataSet (dataSet, MyCalendar.SelectedDate)
    DailyEventDetailRepeater.DataSource=eventsForToday
    DailyEventDetailRepeater.DataBind()
    If (eventsForToday.Tables(0).Rows.Count > 0) Then
        DailyDetailsPanel.Visible = True
        SelectedDate.Text = "Events For " + MyCalendar.SelectedDate.ToLongDateString()
    Else
        DailyDetailsPanel.Visible = False
        SelectedDate.Text = "No Events Scheduled For " + MyCalendar.SelectedDate.ToLongDateString()
    End if
End sub
.
.
.
[HTML SECTION...INSIDE FORM:]
<asp:Calendar id="MyCalendar" runat="server"
SelectedDate="2003/08/05"


 
Old December 1st, 2004, 06:17 PM
Registered User
 
Join Date: Dec 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I had a hard time finding a solution to this as well, though I was using C#. Try this link for a more detailed explanation of how to do it...

http://msdn.microsoft.com/library/de...sDateTopic.asp

[Visual Basic]
<%@ Page Language="VB" AutoEventWireup="True" %>

<html>
<head>

   <script language="VB" runat="server">

        Sub Selection_Change(sender As Object, e As EventArgs)
            Calendar1.TodaysDate = Calendar1.SelectedDate
            Label1.Text = "Today's Date is now " & Calendar1.TodaysDate.ToShortDateString()
        End Sub 'Selection_Change

   </script>

</head>
<body>

   <form runat="server">

      <h3>Calendar Example</h3>

      Select a date on the Calendar control to use as today's date.<br><br>

      <asp:Calendar ID="Calendar1" runat="server"
           SelectionMode="Day"
           ShowGridLines="True"
           OnSelectionChanged="Selection_Change">

         <SelectedDayStyle BackColor="Yellow"
                           ForeColor="Red">
         </SelectedDayStyle>

      </asp:Calendar>

      <br>

      <asp:Label id="Label1" runat=server />

   </form>
</body>
</html>





Similar Threads
Thread Thread Starter Forum Replies Last Post
Calendar like calendar in AJAX in ASP.NET h@ckerz ASP.NET 2.0 Professional 0 February 19th, 2008 12:56 AM
Calendar.SelectedDate and clearing it Quick209 ASP.NET 2.0 Professional 1 January 12th, 2007 02:17 PM
ie calendar gefuller2510 BOOK: CSS Instant Results 3 January 3rd, 2007 07:31 PM
calendar trangd Beginning PHP 2 June 1st, 2004 04:36 PM
Calendar kekohchaa VS.NET 2002/2003 4 April 7th, 2004 05:41 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.