what's a neater way of writing this simple code...

S

Stimp

I'm populating a dropdown list with non-consecutive values (well the
last 3 values are non-consecutive anyway).. What's a shorter way of
writing the following?...

ddLetMaxPrice.Items.Insert(0, New ListItem("No Preference", 999999))
ddLetMaxPrice.Items.Insert(1, New ListItem("100", 100))
ddLetMaxPrice.Items.Insert(2, New ListItem("200", 200))
ddLetMaxPrice.Items.Insert(3, New ListItem("300", 300))
ddLetMaxPrice.Items.Insert(4, New ListItem("400", 400))
ddLetMaxPrice.Items.Insert(5, New ListItem("500", 500))
ddLetMaxPrice.Items.Insert(6, New ListItem("600", 600))
ddLetMaxPrice.Items.Insert(7, New ListItem("700", 700))
ddLetMaxPrice.Items.Insert(8, New ListItem("800", 800))
ddLetMaxPrice.Items.Insert(9, New ListItem("900", 900))
ddLetMaxPrice.Items.Insert(10, New ListItem("1200", 1200))
ddLetMaxPrice.Items.Insert(11, New ListItem("1400", 1400))
ddLetMaxPrice.Items.Insert(12, New ListItem("1600", 1600))
ddLetMaxPrice.Items.Insert(13, New ListItem("1800", 1800))
ddLetMaxPrice.Items.Insert(14, New ListItem("2000+", 999999))

All I can seem to find on the net is to populate an ArrayList with the
values and then use the arraylist as a datasource, but that also
involves a line of code per item.

I'm looking for something like:

var aMaxPriceName = new Array("Not Selected", "2,000", "2,500", "3,000",
"3,500", "4,000", "4,500", "5,000+");
var aMaxPriceValue = new Array(999999999999, 2000, 2500,
3000, 3500, 4000, 4500, 999999999999);

and then to bind that array to the dropdownlist.
Any ideas?
 
S

ScottStoecker

You could try something like this:

Dim List() As String = {100, 200, 300, 400, 500, 600, 700}
DropDownList3.DataSource = List
DropDownList3.DataBind()
DropDownList3.Items.Insert(0, New ListItem("No preference",
999999))
DropDownList3.Items.Insert(DropDownList3.Items.Count, New
ListItem("2000+", 999999))

Hope that helps,
Scott
 
S

S. Justin Gengo

Stimp,

I think you could bind an array vs. the array list that would be easier to
populate.

Dim MyArray as String() = { "100", "200", "300" }

lstPizzaTopping.DataSource = MyArray
lstPizzaTopping.DataBind()


--
Sincerely,

S. Justin Gengo, MCP
Web Developer / Programmer

www.aboutfortunate.com

"Out of chaos comes order."
Nietzsche
 
S

Stimp

You could try something like this:

Dim List() As String = {100, 200, 300, 400, 500, 600, 700}
DropDownList3.DataSource = List
DropDownList3.DataBind()
DropDownList3.Items.Insert(0, New ListItem("No preference",
999999))
DropDownList3.Items.Insert(DropDownList3.Items.Count, New
ListItem("2000+", 999999))

that's probably the best I can do.. thanks!
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top