6 Replies - 15643 Views - Last Post: 02 January 2009 - 01:27 AM Rate Topic: -----

#1 raghavendra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

calendar control using drop down lists

Post icon  Posted 23 December 2008 - 02:31 AM

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

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

Is This A Good Question/Topic? 0
  • +

Replies To: calendar control using drop down lists

#2 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: calendar control using drop down lists

Posted 23 December 2008 - 06: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?

This post has been edited by eclipsed4utoo: 23 December 2008 - 06:51 AM

Was This Post Helpful? 0
  • +
  • -

#3 raghavendra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

Re: calendar control using drop down lists

Posted 23 December 2008 - 10:58 PM

View Posteclipsed4utoo, on 23 Dec, 2008 - 05:50 AM, said:

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.
Was This Post Helpful? 0
  • +
  • -

#4 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: calendar control using drop down lists

Posted 24 December 2008 - 10:09 AM

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...

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 December 2008 - 10:10 AM

Was This Post Helpful? 0
  • +
  • -

#5 raghavendra  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 20
  • Joined: 11-August 08

Re: calendar control using drop down lists

Posted 25 December 2008 - 06:00 AM

Hi ,

Thanks for ur reply i did it like this :
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....
Was This Post Helpful? 0
  • +
  • -

#6 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: calendar control using drop down lists

Posted 25 December 2008 - 09:09 AM

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).
Was This Post Helpful? 0
  • +
  • -

#7 Neill  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 02-January 09

Re: calendar control using drop down lists

Posted 02 January 2009 - 01:27 AM

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"
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1