Wrox Programmer Forums
VB.NET 2002/2003 Basics For coders who are new to Visual Basic, working in .NET versions 2002 or 2003 (1.0 and 1.1).
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB.NET 2002/2003 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 March 2nd, 2005, 11:42 PM
mlf mlf is offline
Registered User
Join Date: Jan 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
Default Listboxes with validation

I am creating a .net project and am adding custom renderers. I have this code for creating the date field into 3 listboxes, the Month, theDay and theYear. I would like to add an on_change() event (or some such mechanism) to change theDay from 1-31 to the appropriate number of days (I have to consider leap years too).

---------------- Beginning of code -------------------------
Imports System.ComponentModel
Imports System.Web.UI

<ToolboxData("<{0}:DateRenderer runat=server></{0}:DateRenderer>")> Class DateRenderer
    Inherits AbstractFieldRenderer

    Private Shared ReadOnly DEFAULT_DATE = Now()

    Private Shared log As log4net.ILog = log4net.LogManager.GetLogger("DateRenderer")

    Public Overloads Sub onInit(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Init

        Dim theMonth As New ListBox
        '' theMonth.Width = Unit.Parse("21pt")
        theMonth.ID = Me.ID & "_theMonth"
        theMonth.Items.Add(New ListItem("Jan", "01"))
        theMonth.Items.Add(New ListItem("Feb", "02"))
        theMonth.Items.Add(New ListItem("Mar", "03"))
        theMonth.Items.Add(New ListItem("Apr", "04"))
        theMonth.Items.Add(New ListItem("May", "05"))
        theMonth.Items.Add(New ListItem("Jun", "06"))
        theMonth.Items.Add(New ListItem("Jul", "07"))
        theMonth.Items.Add(New ListItem("Aug", "08"))
        theMonth.Items.Add(New ListItem("Sep", "09"))
        theMonth.Items.Add(New ListItem("Oct", "10"))
        theMonth.Items.Add(New ListItem("Nov", "11"))
        theMonth.Items.Add(New ListItem("Dec", "12"))

        Dim theDay As New ListBox
        'theDay.Width = Unit.Parse("14pt")
        theDay.ID = Me.ID & "_theDay"
        Dim i As Integer
        For i = 1 To 31
            theDay.Items.Add(New ListItem(i, i))

        Dim theYear As New ListBox
        'theYear.Width = Unit.Parse("28pt")
        theYear.MaxLength = 4
        theYear.ID = Me.ID & "_lastFour"
        Dim x As Integer = System.DateTime.Today.Year
        For i = 1900 To x
            theYear.Items.Add(New ListItem(i, i))

        Dim theMonthRequiredValidator As New RequiredFieldValidator
        theMonthRequiredValidator.ControlToValidate = Me.ID & "_theMonth"
        theMonthRequiredValidator.ErrorMessage = "Choose a month, this field is required."
        theMonthRequiredValidator.Display = ValidatorDisplay.None

        Dim theDayRequiredValidator As New RequiredFieldValidator
        theDayRequiredValidator.ControlToValidate = Me.ID & "_theDay"
        theDayRequiredValidator.ErrorMessage = "Choose a day, this field is required."
        theDayRequiredValidator.Display = ValidatorDisplay.None

        Dim theYearRequiredValidator As New RequiredFieldValidator
        theYearRequiredValidator.ControlToValidate = Me.ID & "_theYear"
        theYearRequiredValidator.ErrorMessage = "Choose a year, this field is required."
        theYearRequiredValidator.Display = ValidatorDisplay.None



    End Sub
End Class
---------------- End of code -------------------------
Thanks for the help!

Similar Threads
Thread Thread Starter Forum Replies Last Post
Listboxes Sub-Listboxes and Table Linking MJB05 Access 4 September 20th, 2005 12:37 PM
Listboxes as Date w/ validation mlf Beginning VB 6 3 March 4th, 2005 09:29 PM
Listboxes and Arrays interrupt Javascript How-To 1 August 2nd, 2004 01:55 PM
Filtering listboxes Bill Snow VB Databases Basics 0 February 5th, 2004 03:32 PM
Listboxes Alaric VS.NET 2002/2003 1 October 29th, 2003 11:54 AM

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