Simple Date Control

I would like to use a date control that simply displays today's date (in MM/dd/yyyy format) and allows the user to use the up/down arrows to change the date. As I see it the calendar control displays the entire month ... this takes up more screen space than I can afford to allot to the control. Does anyone know of a simple control like this? The date picker in VB 6.0 did the trick there but I am developing a web app and using VB .Net.

Thanks.

Comments

  • : I would like to use a date control that simply displays today's date (in MM/dd/yyyy format) and allows the user to use the up/down arrows to change the date. As I see it the calendar control displays the entire month ... this takes up more screen space than I can afford to allot to the control. Does anyone know of a simple control like this? The date picker in VB 6.0 did the trick there but I am developing a web app and using VB .Net.
    :
    : Thanks.
    :

    I usually create 3 drop-downs. One for Months, One For Days, And one for Years.

    Here is what the code would look like in an aspx page ...

    [code]



    [/code]

    [code]
    ' Builds The Drop-Downs
    Public Sub BuildList( _
    ByVal start As Integer, _
    ByVal finish As Integer, _
    ByRef dd As DropDownList)

    dd.Clear

    Dim i As Integer
    For i = start to finish
    With dd.Items
    .Add(New ListItem(i.tostring, i.ToString))
    End With
    Next
    End Sub
    [/code]

    Then when I create a a page ... I can build the drop-down like so ...

    [code]
    Sub Page_Load
    If Not Page.IsPostBack Then
    Call BuildList(1, 12, cboMonths)
    Call BuildList(1, 31, cboDays)
    Call BuildList(Date.Now.Year, _
    Date.Now.AddYears(5).Year, cboYears)
    End If
    End Sub
    [/code]

    If you want to select a date based on a date then you can use the routine below ...

    [code]
    Public Sub SelectDate(ByVal datDate As date)
    ' Code to check to see if date year is within the dropdown limits.
    ' For simplicity I just ignore any errors (For this example)

    On Error Resume Next

    ' Deslect current selections
    cboMonths.SelectedIndex = -1
    cboDays.SelectedIndex = -1
    cboYears.SelectedIndex = -1

    ' Reselect based on date
    cboMonths.Items.FindByValue(datDate.Month.ToString).Selected = True
    cboDays.Items.FindByValue(datDate.Day.ToString).Selected = True
    cboYears.Items.FindByValue(datDate.Year.ToString).Selected = True
    End Sub
    [/code]

    To select todays date you can use the function like so ...

    [code]
    :
    Call SelectDate(Date.Now)
    :
    [/code]

    Hope this gives u some ideas. You can adapt this to display string names for the months and so on.
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

In this Discussion