Click here to Skip to main content
12,823,823 members (58,838 online)
Rate this:
Please Sign up or sign in to vote.
See more: VB VB.NET
can anyone help me,how to display the number of days in the textbox when i select the month in the dropdownlist
Posted 10-Dec-12 21:14pm
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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.
rifayee 11-Dec-12 2:42am
hi friend thanks for ur reply,i do like that only but it shows the particular month 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
numberofdays = 28
End If
End Select
TextBox24.Text = numberofdays
Rate this: bad
Please Sign up or sign in to vote.

Solution 2

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.

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

    Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web01 | 2.8.170308.1 | Last Updated 11 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100