473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Populating a List box with recent dates

I am having a interesting issue. I work for a University's Career
Services department. We collect data from recent grads. I am
recreating the online survey we use. I am trying to populate the
graduation date with 4 dates. May **, June **, August **, December **.
The "**" represents the year of graduation. To prevent having to
constantly update this survey I'd like to dynamically create this
values. So at page load I want it to check the server time and only
show the months from the past year. IE since Today is June 07 the
values would read June 07, May 07, December 06, August 06. Then in
August It would read August 07, June 07, May 07, December 06. Etc... I
am trying to think of a clever way to do this and just can not do
this. Anyone have an idea???

Jun 1 '07 #1
13 1250
"djjohnst" <dj******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
Anyone have an idea???
List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
}
--
http://www.markrae.net

Jun 1 '07 #2
How about something like...

DateTime dt = DateTime.Today();

for (int iLoop = 0; iLoop < 4; iLoop++)
{
ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
dt)));
dt = dt.DateAdd("MM", -3, dt);
}

Dunc
http://www.fluidfoundation.com

On 1 Jun, 14:08, djjohnst <djjoh...@gmail.comwrote:
I am having a interesting issue. I work for a University's Career
Services department. We collect data from recent grads. I am
recreating the online survey we use. I am trying to populate the
graduation date with 4 dates. May **, June **, August **, December **.
The "**" represents the year of graduation. To prevent having to
constantly update this survey I'd like to dynamically create this
values. So at page load I want it to check the server time and only
show the months from the past year. IE since Today is June 07 the
values would read June 07, May 07, December 06, August 06. Then in
August It would read August 07, June 07, May 07, December 06. Etc... I
am trying to think of a clever way to do this and just can not do
this. Anyone have an idea???

Jun 1 '07 #3
On Jun 1, 3:25 pm, "Mark Rae" <m...@markNOSPAMrae.netwrote:
"djjohnst" <djjoh...@gmail.comwrote in message

news:11**********************@p77g2000hsh.googlegr oups.com...
Anyone have an idea???

List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);

}

--http://www.markrae.net
Well done, Mark!

Jun 1 '07 #4
"Alexey Smirnov" <al************@gmail.comwrote in message
news:11**********************@u30g2000hsc.googlegr oups.com...
Well done, Mark!
LOL!
--
http://www.markrae.net

Jun 1 '07 #5
"Dunc" <du**********@gmail.comwrote in message
news:11**********************@g4g2000hsf.googlegro ups.com...
DateTime dt = DateTime.Today();

for (int iLoop = 0; iLoop < 4; iLoop++)
{
ddlMyDropDown.Items.Add(new ListItem(String.Format("{0:MMM yy}",
dt)));
dt = dt.DateAdd("MM", -3, dt);
}
Suppose you start today, what are the four dates which your code will add to
the DropDownList...?
--
http://www.markrae.net

Jun 1 '07 #6
Just a bit of modification to Mark's code to output it as djjohnst was looking
for, in the "June XX" format):

List<StringlstDates = new List<String>();
DateTime dtmStart = new DateTime(DateTime.Now.Year, DateTime.Now.Month,
1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart.ToString("MMMM yy"));
}
dtmStart = dtmStart.AddMonths(-1);
}

ddlGradDates.DataSource = lstDates;
ddlGradDates.DataBind();

- Converted it from a list collection of DateTimes to Strings; maybe a KVP
to keep the "data" and presentation apart may be a solution if the two need
to be different.

- Added the MMMM yy to output the long Month name and short year.

HTH.

-dl

---
David R. Longnecker
Web Developer
http://blog.tiredstudent.com
"djjohnst" <dj******@gmail.comwrote in message
news:11**********************@p77g2000hsh.googlegr oups.com...
>Anyone have an idea???
List<DateTimelstDates = new List<DateTime>();
DateTime dtmStart = new DateTime(DateTime.Now.Year,
DateTime.Now.Month, 1);
while (lstDates.Count < 4)
{
if (dtmStart.Month == 5
|| dtmStart.Month == 6
|| dtmStart.Month == 8
|| dtmStart.Month == 12)
{
lstDates.Add(dtmStart);
}
dtmStart = dtmStart.AddMonths(-1);
}

Jun 1 '07 #7
"David Longnecker" <dl*********@community.nospamwrote in message
news:46*************************@msnews.microsoft. com...
Just a bit of modification to Mark's code to output it as djjohnst was
looking for, in the "June XX" format):
True enough - I took the final formatting "as read", and assumed that the
it was the actual date generation that was causing the OP problems... :-)
--
http://www.markrae.net

Jun 1 '07 #8
As of today i would want it to display the following options
June 07
May 07
Dec 06
August 06

Jun 1 '07 #9
"djjohnst" <dj******@gmail.comwrote in message
news:11**********************@q69g2000hsb.googlegr oups.com...
As of today i would want it to display the following options
June 07
May 07
Dec 06
August 06

Yes, I know...
--
http://www.markrae.net

Jun 1 '07 #10
Forgive me. I am really new to ASP.net. Where would i put that code? I
tried in the Head section and it did not work.

Jun 1 '07 #11
"djjohnst" <dj******@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
Forgive me. I am really new to ASP.net. Where would i put that code? I
tried in the Head section and it did not work.
The code I gave you is C#, which runs server-side so it can't go in your
page's header section...

Are you using in-line server-side code or code-behind...?
--
http://www.markrae.net

Jun 1 '07 #12
in-line. Do you think it would be better to do code behind?

Jun 1 '07 #13
"djjohnst" <dj******@gmail.comwrote in message
news:11**********************@m36g2000hse.googlegr oups.com...
in-line.
OK.
Do you think it would be better to do code behind?
Wouldn't make the slightest difference...
--
http://www.markrae.net

Jun 1 '07 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: msnews.microsoft.com | last post by:
I'd like to hear your thoughts on best methods for populating drop down list controls. I have states and countries drop down lists that don't change often, so naturally I "hard code" them in the...
4
by: Irishmaninusa | last post by:
I am trying to populate a drop down on a form with the contents of a recordset and I am getting the following values in the dropdown System.Data.DataRowView and not the expected content that...
6
by: P K | last post by:
I have a listbox which I am populating on the client (it contains a list of dates selected from calender). The listbox is a server control. When I get to the server after postback by selecting an...
8
by: jack-b | last post by:
Hi, I have a list box which displays countries names and a second listbox which displays their cites (based on the selection made in ListBox 1) If the user selects USA i want to display cities...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.