Click here to Skip to main content
15,867,756 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
can anyone help me,how to display the number of days in the textbox when i select the month in the dropdownlist
Posted

You can use DateTime.DaysInMonth Method[^] to get the number of days in a month and assign the result to your textbox in the SelectedIndexChanged event of your dropdown.
 
Share this answer
 
Comments
rifayee 11-Dec-12 2:42am    
hi friend thanks for ur reply,i do like that only but it shows the particular month only..here is the code
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim days As Integer
days = DateTime.DaysInMonth(2012, 2)


TextBox20.Text = days

End Sub
__TR__ 11-Dec-12 2:56am    
I did not understand your comment. What exactly is the problem with the code you have posted?
rifayee 11-Dec-12 6:20am    
can anybody show one example
__TR__ 11-Dec-12 6:31am    
What have you tried so far ?
rifayee 11-Dec-12 6:42am    
Dim numberofdays, monthnumber As Integer
Dim IsLeapYear As Boolean = DateTime.IsLeapYear(year)
If year >= 1 AndAlso year <= 12 Then
Select Case monthnumber
Case 1, 3, 5, 7, 8, 10, 12
numberofdays = 31
Case 4, 6, 9, 11
numberofdays = 30
Case 2
If IsLeapYear Then
numberofdays = 29
Else
numberofdays = 28
End If
End Select
TextBox24.Text = numberofdays
Exactly how you do this depends on what you load into your DropDownList in the first place (a string would be different from a number, would be different from a Month class) - and also on what environment you are trying to work. The solution for a web based project would be different from that for a windows application (in that it would involve Javascript to save a postback).

But the basic structure is the same: handle the Changed event fro the drop down, get teh current value, then either look it up in a table or use it's parameters to access the number of days. Then look at the year to check for leap years / February problems, and set teh value.

But we can't be more specific without knowing a lot more about your environment.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900