Showing posts with label lists. Show all posts
Showing posts with label lists. Show all posts

Monday, March 26, 2012

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.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" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.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.
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" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.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.
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:uyIxbbCUEHA.1012@.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" <web001@.27NOSPAMlamps.com> wrote in message
> news:OyUB0xBUEHA.1012@.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.

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.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" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.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.
>
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" <web001@.27NOSPAMlamps.com> wrote in message
news:OyUB0xBUEHA.1012@.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.
>
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:uyIxbbCUEHA.1012@.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" <web001@.27NOSPAMlamps.com> wrote in message
> news:OyUB0xBUEHA.1012@.TK2MSFTNGP09.phx.gbl...
> Lists.
as:
with
>

Friday, March 16, 2012

Populating Drop Down Lists Based on Another DDL

Sounds like your repopulating the first dropdown in the load event. Try
wrapping the code that populates the first drop down in a
"IsPostBack==False" type check.

"Ben Arthur" <skchbs@dotnet.itags.org.yahoo.com> wrote in message
news:uHDS6CHAEHA.4080@dotnet.itags.org.TK2MSFTNGP09.phx.gbl...
> OK...assume the first ddl has 2 values"USA" & Australia", when i select
> USA, it populates the states correctly in the second ddl, but then if i
> select australia also, as it is autopostback, it comes back to USA as
> selected n so i cannot get the second DDL to populate to values for
> Australia...the datagrid however does bind correctly according to the
> states selected...
> Please let me know if I shoudl explain better....
> Thanks for ur time
> Ben
>
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!Yes ! Thanks, that worked...but i m not sure of how to handle
postbacks....i.e i load the first ddl only the first time, it loads the
USA and australia, then i select one of them, it loads second ddl
accordingly and builds the datagrid,but if i select australia, it
populates the second ddl but does not bind the grid.....though the
binding is not related to postback but to the selectedindexhanged(i shud
mention there is only value for the second ddl in my DB for first
ddl=australia)...is it related to the postback ...or is it because there
is only one value?
Thanks again for ur help.
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
My usual process for this is...

Put your grid-data-binding in a method/function/sub of its own. Call this
from the page load (wrapped in a isPostBack==False) then in each of your
drop down list events you can call the grid databind method.

BTW, do you really need a grid, they are very "heavy".

"Ben Arthur" <skchbs@.yahoo.com> wrote in message
news:u5jF9ZHAEHA.2800@.tk2msftngp13.phx.gbl...
> Yes ! Thanks, that worked...but i m not sure of how to handle
> postbacks....i.e i load the first ddl only the first time, it loads the
> USA and australia, then i select one of them, it loads second ddl
> accordingly and builds the datagrid,but if i select australia, it
> populates the second ddl but does not bind the grid.....though the
> binding is not related to postback but to the selectedindexhanged(i shud
> mention there is only value for the second ddl in my DB for first
> ddl=australia)...is it related to the postback ...or is it because there
> is only one value?
> Thanks again for ur help.
> Ben
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
thanks a lot...i had to put the binding code in postback part too n now
it works fine...

Thanks again
Ben

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!