473,836 Members | 1,948 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 14225
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****@27NOSPA Mlamps.com> wrote in message
news:Oy******** ******@TK2MSFTN GP09.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.Globaliz ation;

dtfi = new DateTimeFormatI nfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthNa me(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****@27NOSPA Mlamps.com> wrote in message
news:Oy******** ******@TK2MSFTN GP09.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:

DateTimeFormatI nfo dtfi = new DateTimeFormatI nfo();

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******** ******@TK2MSFTN GP09.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.Globaliz ation;

dtfi = new DateTimeFormatI nfo();
for (int month = 1; month < 13; month ++)
{
ListItem li = new ListItem();
li.Text = dtfi.GetMonthNa me(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****@27NOSPA Mlamps.com> wrote in message
news:Oy******** ******@TK2MSFTN GP09.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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
11240
by: julian | last post by:
hi I was wondering if anyone can help me out on this.... I have dynamcally populated a drop down menu with data from an access database using ASP. The values seem fine, however when i pass them to the next page (using form get method) the whitespaces in the values are ignored. For example with <option value=jim jones> then only "jim" gets passed to the next page not "jim jones". I have viewed the source created on the dynamic page and...
1
2493
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 aspx page. But the problem is these tend to really slow the development -- it takes up to 15 seconds for the page to come up in VS.NET design environment, so I'm thinking about taking these out and populating the controls dynamically using the...
1
2053
by: csgraham74 | last post by:
Hi Guys, I am currently building a web aplication in ASP.Net. On the onload event of a page a have a function to populate the many drop down lists on my page. I have one parameter table which stores all the values e.g. Title,Type,Status,Property,Occupation. I am using a sql string and then populationg my drop down list
7
6315
by: Miguel Dias Moura | last post by:
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:
1
296
by: puja | last post by:
hi all, I have a requirement where I need to populate drop down list (which is not run at server control. i.e it is an html control ) using server side code in C#? How can I add option values to drop down list in page load event. Thanks puja
2
1925
by: tom c | last post by:
I have a dropdown list box on an ASP.Net 1.1 webform. I populate it from a dataset in code. Everything looks fine and I can see all the values in the dropdownlist. I can select a value and I see that new selected value in the list box. However, when I look for the values in code, I see the original value from the list box. The one that was loaded first and showed up before I selected a new one. This is the code I use to look at the...
3
6901
by: Yi Chen | last post by:
We have a drop down list on a PHP page, with several product names, and when people click one item, we will refresh the same page with the product name as parameter, and in turn we want to include a HTML file into the content area of the same page. I know it is recommended to put everything into database, but we want the web site to be very "portable", so the drop-downlist and the content should both in text files. Let's say the...
3
7363
by: penny111 | last post by:
Hi there, For my application, i need to have 3 drop down lists 1. drop down list of folder names 2. drop down list of documents in the folder selected 3. drop down list of instances of the document selected (my application uses the BusinessObjects Java Web Services SDK) The 2nd list is dependent on the 1st, while the 3rd list is dependent on the 2nd. In other words, this is what i want my application to do -select a folder from the...
3
2329
by: DaveRook | last post by:
Hi I am using C# and Access databse for a web site. I have a drop down list which I need to populate dynamically according to results in a database. Example There will be 1 drop down list on the page which offers 3 makes of cars: Mazda, Honda, Ford
0
9658
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10824
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10533
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10579
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9362
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6975
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5644
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4443
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4003
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.