dropdown list to select day,month & year using for loop

S

sonum

I am creating a custom control with 3 dropdownlists (day, month,
year)
which I will use as a date selector. I want to be able to reuse all my
code
and cut programming repetition down a lot (I don't mind spending a lot
of
time on something if I don't have to do it again).

My question is, with the day selector, how should I store a list of
numbers
from 1 to 31 to bind to the dropdownlistbox? I could run a loop and
create
it like that but why not just have an existing array or enum or
something.


With the month selector I am using an enumerator to hold all the month
names
but it doesnt seem efficient to use one for a list of numbers.


Does anyone have any suggestions? If you help me out I will even give
you
this control when I'm finished (and anyone who wants it).
 
G

Guest

I am creating  a custom control with 3 dropdownlists (day, month,
year)
which I will use as a date selector. I want to be able to reuse all my
code
and cut programming repetition down a lot (I don't mind spending a lot
of
time on something if I don't have to do it again).

My question is, with the day selector, how should I store a list of
numbers
from 1 to 31 to bind to the dropdownlistbox? I could run a loop and
create
it like that but why not just have an existing array or enum or
something.

With the month selector I am using an enumerator to hold all the month
names
but it doesnt seem efficient to use one for a list of numbers.

Does anyone have any suggestions? If you help me out I will even give
you
this control when I'm finished (and anyone who wants it).

if you don't need to have local translation of names, then you can
just have

Months() As String = {"January", "February", "March", "April", "May",
"June", "July", "August", "September", "October", "November",
"December"}
 
C

Cowboy \(Gregory A. Beamer\)

WIndows forms or ASP.NET?

With WIndows forms, you can rebuild the days, based on the year and month
(overall month, but you do have February changing based on year). With
ASP.NET, you rebuild the select with JavaScript, which means you have to
emit it.

The other issue you have is one of culture. Not as big with a windows app,
as you simply change config elements. With a web control, however, you
either have to ship the resource file with the control (not impossible, but
a bit more difficult, as it is an extra file to have missing) or you have to
encapsulate the logic, which means you have to do more work up front.
 
A

Andrew Morton

Cowboy said:
The other issue you have is one of culture. Not as big with a windows
app, as you simply change config elements. With a web control,
however, you either have to ship the resource file with the control
(not impossible, but a bit more difficult, as it is an extra file to
have missing) or you have to encapsulate the logic, which means you
have to do more work up front.

With a web app it's as simple as generating the month names server-side if,
in the <system.web> section of web.config, you have

<globalization culture="auto" uiCulture="auto" />

That way, datetimeVar.tostring("MMMM") will generate month names in the
language the browser says it's set to.

If that's what you meant by the culture issue...

Andrew
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,754
Messages
2,569,528
Members
45,000
Latest member
MurrayKeync

Latest Threads

Top