Re: asp.net calendar enhancement

Discussion in 'ASP .Net' started by Fred., Jun 25, 2003.

  1. Fred.

    Fred. Guest

    Not sure how you intend to get input from the user but here's a sample
    that allows selection from a listbox.

    Drop the following code and codebehind into an ASPX page named
    CustCal.
    Set the Default namespace of the project to CSWeb.
    Give it a try, nothing that this sample only does future navigation

    (Is the CN tower in the clouds today?)

    - Fred

    **************ASPX code**********************
    <%@ Page Language="vb" AutoEventWireup="false"
    Codebehind="CustCal.aspx.vb" Inherits="VBWeb.CustCal" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <HTML>
    <HEAD>
    <title>Birthday Calendar</title>
    <meta name="GENERATOR" content="Microsoft Visual Studio.NET 7.0">
    <meta name="CODE_LANGUAGE" content="Visual Basic 7.0">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema"
    content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <asp:Calendar id="Calendar1" style="Z-INDEX: 103; LEFT: 27px;
    POSITION: absolute; TOP: 21px" runat="server" BackColor="#C0FFFF"
    BorderStyle="Solid" Height="276px" Width="328px" ShowGridLines="True">
    <DayStyle Font-Size="Smaller" Font-Names="Arial"></DayStyle>
    <DayHeaderStyle Font-Size="XX-Small" Font-Names="Arial"
    BackColor="#FFC0FF"></DayHeaderStyle>
    <TitleStyle Font-Names="Arial"
    BackColor="#C0C0FF"></TitleStyle>
    </asp:Calendar>
    <asp:ListBox id="lstMonth" style="Z-INDEX: 102; LEFT: 309px;
    POSITION: absolute; TOP: 27px" runat="server" Font-Names="Arial"
    Font-Size="XX-Small" Height="163px" Width="41px" Visible="False"
    AutoPostBack="True"></asp:ListBox>
    </form>
    </body>
    </HTML>

    ************** code behind **********************
    Public Class CustCal
    Inherits System.Web.UI.Page
    Protected WithEvents Calendar1 As System.Web.UI.WebControls.Calendar
    Protected WithEvents lstMonth As System.Web.UI.WebControls.ListBox

    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()
    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    InitializeComponent()
    End Sub

    Private Sub Calendar1_VisibleMonthChanged(ByVal sender As
    System.Object, ByVal e As
    System.Web.UI.WebControls.MonthChangedEventArgs) Handles
    Calendar1.VisibleMonthChanged
    'effectively cancel the navigation
    Calendar1.VisibleDate = e.PreviousDate
    'get a new month to display
    ShowMonthSelector(e.PreviousDate)
    End Sub

    Private Function ShowMonthSelector(ByVal dtCurrent As Date) As Date
    Dim i As Integer
    'display an ordered list starting with the next month
    lstMonth.Items.Clear()
    For i = 1 To 12
    lstMonth.Items.Add(Format(dtCurrent.AddMonths(i), "MMM"))
    Next
    lstMonth.Visible = True
    End Function

    Private Sub lstMonth_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    lstMonth.SelectedIndexChanged
    Dim iMonth As Integer
    Dim iYear As Integer
    'set the calendar to the selecteed month
    lstMonth.Visible = False
    iMonth = Calendar1.VisibleDate.Month + lstMonth.SelectedIndex + 1
    iYear = Calendar1.VisibleDate.Year
    If iMonth > 12 Then
    iYear += 1
    iMonth = iMonth Mod 12
    End If
    Calendar1.VisibleDate = New Date(iYear, iMonth, 1)
    End Sub
    End Class



    "Marlene" <> wrote in message news:<0bb801c33b2a$63a99830$>...
    > Hello,
    >
    > I'm using the VB.net calendar for my aspx page and I was
    > wondering if it is possible to enhance it so that the
    > user can directly select which month and which year they
    > would like to go to rather than only being able to go the
    > next or previous months. If it is, how do I do this?
    >
    > Thanks,
    > Marlene
    Fred., Jun 25, 2003
    #1
    1. Advertising

  2. Fred.

    Cann Guest

    http://cheapdevtools.com/product/product.asp?ProdID=246

    > "Marlene" <> wrote in message news:<0bb801c33b2a$63a99830$>...
    > > Hello,
    > >
    > > I'm using the VB.net calendar for my aspx page and I was
    > > wondering if it is possible to enhance it so that the
    > > user can directly select which month and which year they
    > > would like to go to rather than only being able to go the
    > > next or previous months. If it is, how do I do this?
    > >
    > > Thanks,
    > > Marlene
    Cann, Jul 15, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Marlene

    Re: asp.net calendar enhancement

    Marlene, Jun 25, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    950
    Marlene
    Jun 25, 2003
  2. randau
    Replies:
    30
    Views:
    1,370
    Travis Newbury
    May 20, 2005
  3. Stephen

    nested if enhancement?

    Stephen, Mar 1, 2004, in forum: XML
    Replies:
    1
    Views:
    402
    Dimitre Novatchev [MVP XML]
    Mar 1, 2004
  4. redguardtoo
    Replies:
    0
    Views:
    299
    redguardtoo
    Jul 26, 2004
  5. redguardtoo
    Replies:
    0
    Views:
    319
    redguardtoo
    Jul 26, 2004
Loading...

Share This Page