Chat LIVE With Programming Experts! There Are 23 Online Right Now...

Welcome to Dream.In.Code
Become a ASP.NET Expert!

Join 244,310 ASP.NET Programmers for FREE! Get instant access to thousands of ASP.NET experts, tutorials, code snippets, and more! There are 870 people online right now. Registration is fast and FREE... Join Now!




calendar control using drop down lists

 
Reply to this topicStart new topic

calendar control using drop down lists

raghavendra
23 Dec, 2008 - 01:31 AM
Post #1

New D.I.C Head
*

Joined: 11 Aug, 2008
Posts: 20



Thanked: 1 times
My Contributions
Hi all,

I am having a requirement tht i have to select the date from 3 drop downlists for date, month and year combo boxes. I already wrote a code for a calendar control tht when selected will be displayed in the adjacent text box. but now for a date of birth u cant ask people to go back to the year tht they have born(may be around 84 ) then my code is of useless thts y i am asking for a drop down list calendar control.
My code goes here for the old calendar control

CODE
Protected Sub btndob_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btndob.Click
        Try
            If (txtdob.Text.Trim() IsNot DBNull.Value) Then
                Calendar1.SelectedDate = Convert.ToDateTime(txtdob.Text)
            End If
        Catch ex As Exception
            IsDate(txtdob.Text)
        End Try
        Calendar1.Visible = True
    End Sub

    Protected Sub Calendar1_SelectionChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles Calendar1.SelectionChanged
        txtdob.Text = DateTime.Parse(Calendar1.SelectedDate).ToString()
        Calendar1.Visible = False
    End Sub

How can we do tht any help or suggestions for performing this task......



any help or suggestion is greatly appreciated...
THanks in advance..
Raghu


User is offlineProfile CardPM
+Quote Post


eclipsed4utoo
RE: Calendar Control Using Drop Down Lists
23 Dec, 2008 - 05:50 AM
Post #2

D.I.C Lover
Group Icon

Joined: 21 Mar, 2008
Posts: 1,170



Thanked: 117 times
Dream Kudos: 125
My Contributions
AJAX has a great Calendar control that acts like a drop-down list.

or do you want individual dropdown lists for the month, day, and year?

This post has been edited by eclipsed4utoo: 23 Dec, 2008 - 05:51 AM
User is offlineProfile CardPM
+Quote Post

raghavendra
RE: Calendar Control Using Drop Down Lists
23 Dec, 2008 - 09:58 PM
Post #3

New D.I.C Head
*

Joined: 11 Aug, 2008
Posts: 20



Thanked: 1 times
My Contributions
QUOTE(eclipsed4utoo @ 23 Dec, 2008 - 05:50 AM) *

AJAX has a great Calendar control that acts like a drop-down list.

or do you want individual dropdown lists for the month, day, and year?




Ya actually iu wanted individual drop down lists for date, month and year also how to populate the year combo box programmatically?

Thanku,
Raghu.




User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Calendar Control Using Drop Down Lists
24 Dec, 2008 - 09:09 AM
Post #4

D.I.C Lover
Group Icon

Joined: 21 Mar, 2008
Posts: 1,170



Thanked: 117 times
Dream Kudos: 125
My Contributions
not that hard to do individual dropdown lists. add a dropdownlist to the form, go to the "Items" property and input all of the values.

after all of the values are in the three dropdownlists, you can use this to get the date...

CODE

protected void Button1_Click(object sender, EventArgs e)
{
    DateTime dtmDate;

    // Assuming that you named the three dropdownlists accordingly
    string strDate = string.Format("{0}/{1}/{2}", dropdownlistMonth.Text, dropdownlistDay.Text, dropdownlistYear.Text);
    
    dtmDate = DateTime.Parse(strDate);
}


you could also add the values to the dropdownlists through code instead of having to type them all in.

This post has been edited by eclipsed4utoo: 24 Dec, 2008 - 09:10 AM
User is offlineProfile CardPM
+Quote Post

raghavendra
RE: Calendar Control Using Drop Down Lists
25 Dec, 2008 - 05:00 AM
Post #5

New D.I.C Head
*

Joined: 11 Aug, 2008
Posts: 20



Thanked: 1 times
My Contributions
Hi ,

Thanks for ur reply i did it like this :
CODE
If Not IsPostBack Then
            Dim i As Integer
            Dim values As New ArrayList
            For i = 1970 To Today.Year
                values.Add(i)
                ddlyear.DataSource = values
                ddlyear.DataBind()
                ddlyearj.DataSource = values
                ddlyearj.DataBind()
            Next
        End If
        d = (ddlday.SelectedItem.Value & ddlmonth.SelectedItem.Value & ddlyear.SelectedItem.Value).ToString()

        s = (ddldatej.SelectedItem.Value & ddlmonthj.SelectedItem.Value & ddlyearj.SelectedItem.Value).ToString()


My problem with the date capturing is done but now how to determine whether the user selects feb 30 then its bug in my code how to fix it??
Any suggestions please....
User is offlineProfile CardPM
+Quote Post

eclipsed4utoo
RE: Calendar Control Using Drop Down Lists
25 Dec, 2008 - 08:09 AM
Post #6

D.I.C Lover
Group Icon

Joined: 21 Mar, 2008
Posts: 1,170



Thanked: 117 times
Dream Kudos: 125
My Contributions
you can do two things.

1. you can make the page postback on the change in month. This way, you can set the day drop down to 28 for February(29 for a leap year).

or

2. you could just catch the bad date. I believe the "DateTime.Parse" should catch February 30th as a bad date(though I haven't tested that).
User is offlineProfile CardPM
+Quote Post

Neill
RE: Calendar Control Using Drop Down Lists
2 Jan, 2009 - 12:27 AM
Post #7

New D.I.C Head
*

Joined: 1 Jan, 2009
Posts: 2


My Contributions
I use a Textbox to display the date selected in the three dropdownlists and then use a RangeValidator of Type="Date" to validate the entry in the textbox.
If you prefer, you can just set the TextBox property Visible="false"
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 7/4/09 07:25PM

Live ASP.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

ASP.NET Tutorials

Reference Sheets

ASP.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month