471,072 Members | 1,406 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Populate a Drop Down List

Hello,

i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists.
Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
DAY, MONTH, and YEAR.

I don't want to insert the values and text to each drop down list.

So i want to create a script that populates a certain Drop Down List with
certain values when page loads such as:

Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ....

This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.

Can you help me out?

Thank You,
Miguel

P.S: I am working with ASP.NET / VB.
Nov 18 '05 #1
3 13942
First thing is to remove the word "script" from your vocabulary. VB .NET is
not VBScript.

You could write some code in the .aspx.vb (code-behind) Page_Load event that
will populate the drop down lists by determining today's date (now) and then
use the various methods of the now value to extract the day, month and year.
Then, via looping, you can build up the items on the lists.
"Miguel Dias Moura" <we****@27NOSPAMlamps.com> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
Hello,

i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
DAY, MONTH, and YEAR.

I don't want to insert the values and text to each drop down list.

So i want to create a script that populates a certain Drop Down List with
certain values when page loads such as:

Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ....

This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.

Can you help me out?

Thank You,
Miguel

P.S: I am working with ASP.NET / VB.

Nov 18 '05 #2
Create a ListItem. Set the value and the text properties and then add it to
the drop down list. I'm not sure about VB.Net but in C# it would be
something like this:

using System.Globalization;

dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month;
ddlMonth.Items.Add(li);
}

Do basically the same thing for each drop down list. Translating the C# to
VB should be pretty straight forward.

Hope this helps,

Dale
"Miguel Dias Moura" <we****@27NOSPAMlamps.com> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
Hello,

i have an ASP.NET / VB page where i have a few 4 groups of Drop Down Lists. Each group of Drop Down Lists include 3 Drop Down Lists for date such as:
DAY, MONTH, and YEAR.

I don't want to insert the values and text to each drop down list.

So i want to create a script that populates a certain Drop Down List with
certain values when page loads such as:

Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ....

This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.

Can you help me out?

Thank You,
Miguel

P.S: I am working with ASP.NET / VB.

Nov 18 '05 #3
One obvious error in my code, make 2nd line:

DateTimeFormatInfo dtfi = new DateTimeFormatInfo();

But then, you have to convert the concept into VB.Net anyway, so it probably
didn't throw you too much.

Good luck

Dale

"DalePres" <don-t-spa-m-me@lea-ve-me-a-lone--.com> wrote in message
news:uy**************@TK2MSFTNGP09.phx.gbl...
Create a ListItem. Set the value and the text properties and then add it to the drop down list. I'm not sure about VB.Net but in C# it would be
something like this:

using System.Globalization;

dtfi = new DateTimeFormatInfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthName(month);
li.Value = month;
ddlMonth.Items.Add(li);
}

Do basically the same thing for each drop down list. Translating the C# to VB should be pretty straight forward.

Hope this helps,

Dale
"Miguel Dias Moura" <we****@27NOSPAMlamps.com> wrote in message
news:Oy**************@TK2MSFTNGP09.phx.gbl...
Hello,

i have an ASP.NET / VB page where i have a few 4 groups of Drop Down

Lists.
Each group of Drop Down Lists include 3 Drop Down Lists for date such as: DAY, MONTH, and YEAR.

I don't want to insert the values and text to each drop down list.

So i want to create a script that populates a certain Drop Down List with certain values when page loads such as:

Day: 1,2,3,4,5,...
Month: January, February, ..., December
Year: 2004, 2003, 2002, 2001, ....

This way in that script i will be able to control how all the Drop Down
Lists are populated just bu changing the script.

Can you help me out?

Thank You,
Miguel

P.S: I am working with ASP.NET / VB.


Nov 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by msnews.microsoft.com | last post: by
1 post views Thread by csgraham74 | last post: by
7 posts views Thread by Miguel Dias Moura | last post: by
1 post views Thread by puja | last post: by
2 posts views Thread by tom c | last post: by
reply views Thread by leo001 | last post: by

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.