473,791 Members | 3,015 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

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.I tems.Insert(0, New ListItem("No Preference", 999999))
ddLetMaxPrice.I tems.Insert(1, New ListItem("100", 100))
ddLetMaxPrice.I tems.Insert(2, New ListItem("200", 200))
ddLetMaxPrice.I tems.Insert(3, New ListItem("300", 300))
ddLetMaxPrice.I tems.Insert(4, New ListItem("400", 400))
ddLetMaxPrice.I tems.Insert(5, New ListItem("500", 500))
ddLetMaxPrice.I tems.Insert(6, New ListItem("600", 600))
ddLetMaxPrice.I tems.Insert(7, New ListItem("700", 700))
ddLetMaxPrice.I tems.Insert(8, New ListItem("800", 800))
ddLetMaxPrice.I tems.Insert(9, New ListItem("900", 900))
ddLetMaxPrice.I tems.Insert(10, New ListItem("1200" , 1200))
ddLetMaxPrice.I tems.Insert(11, New ListItem("1400" , 1400))
ddLetMaxPrice.I tems.Insert(12, New ListItem("1600" , 1600))
ddLetMaxPrice.I tems.Insert(13, New ListItem("1800" , 1800))
ddLetMaxPrice.I tems.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(999999999 999, 2000, 2500,
3000, 3500, 4000, 4500, 999999999999);

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

"I hear ma train a comin'
.... hear freedom comin"
Nov 19 '05 #1
5 1215
You could try something like this:

Dim List() As String = {100, 200, 300, 400, 500, 600, 700}
DropDownList3.D ataSource = List
DropDownList3.D ataBind()
DropDownList3.I tems.Insert(0, New ListItem("No preference",
999999))
DropDownList3.I tems.Insert(Dro pDownList3.Item s.Count, New
ListItem("2000+ ", 999999))

Hope that helps,
Scott

Nov 19 '05 #2
vb.net? or c#
Stimp wrote:
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.I tems.Insert(0, New ListItem("No Preference", 999999))
ddLetMaxPrice.I tems.Insert(1, New ListItem("100", 100))
ddLetMaxPrice.I tems.Insert(2, New ListItem("200", 200))
ddLetMaxPrice.I tems.Insert(3, New ListItem("300", 300))
ddLetMaxPrice.I tems.Insert(4, New ListItem("400", 400))
ddLetMaxPrice.I tems.Insert(5, New ListItem("500", 500))
ddLetMaxPrice.I tems.Insert(6, New ListItem("600", 600))
ddLetMaxPrice.I tems.Insert(7, New ListItem("700", 700))
ddLetMaxPrice.I tems.Insert(8, New ListItem("800", 800))
ddLetMaxPrice.I tems.Insert(9, New ListItem("900", 900))
ddLetMaxPrice.I tems.Insert(10, New ListItem("1200" , 1200))
ddLetMaxPrice.I tems.Insert(11, New ListItem("1400" , 1400))
ddLetMaxPrice.I tems.Insert(12, New ListItem("1600" , 1600))
ddLetMaxPrice.I tems.Insert(13, New ListItem("1800" , 1800))
ddLetMaxPrice.I tems.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(999999999 999, 2000, 2500,
3000, 3500, 4000, 4500, 999999999999);

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

"I hear ma train a comin'
... hear freedom comin"


Nov 19 '05 #3
Either.. I'm working in VB, but can translate from C# :)

On Fri, 14 Oct 2005 parez <ps*****@gmail. com> wrote:
vb.net? or c#
Stimp wrote:
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.I tems.Insert(0, New ListItem("No Preference", 999999))
ddLetMaxPrice.I tems.Insert(1, New ListItem("100", 100))
ddLetMaxPrice.I tems.Insert(2, New ListItem("200", 200))
ddLetMaxPrice.I tems.Insert(3, New ListItem("300", 300))
ddLetMaxPrice.I tems.Insert(4, New ListItem("400", 400))
ddLetMaxPrice.I tems.Insert(5, New ListItem("500", 500))
ddLetMaxPrice.I tems.Insert(6, New ListItem("600", 600))
ddLetMaxPrice.I tems.Insert(7, New ListItem("700", 700))
ddLetMaxPrice.I tems.Insert(8, New ListItem("800", 800))
ddLetMaxPrice.I tems.Insert(9, New ListItem("900", 900))
ddLetMaxPrice.I tems.Insert(10, New ListItem("1200" , 1200))
ddLetMaxPrice.I tems.Insert(11, New ListItem("1400" , 1400))
ddLetMaxPrice.I tems.Insert(12, New ListItem("1600" , 1600))
ddLetMaxPrice.I tems.Insert(13, New ListItem("1800" , 1800))
ddLetMaxPrice.I tems.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(999999999 999, 2000, 2500,
3000, 3500, 4000, 4500, 999999999999);

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

"I hear ma train a comin'
... hear freedom comin"

--

"I hear ma train a comin'
.... hear freedom comin"
Nov 19 '05 #4
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
"Stimp" <re*@spumco.com > wrote in message
news:sl******** ********@carbon .redbrick.dcu.i e...
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.I tems.Insert(0, New ListItem("No Preference", 999999))
ddLetMaxPrice.I tems.Insert(1, New ListItem("100", 100))
ddLetMaxPrice.I tems.Insert(2, New ListItem("200", 200))
ddLetMaxPrice.I tems.Insert(3, New ListItem("300", 300))
ddLetMaxPrice.I tems.Insert(4, New ListItem("400", 400))
ddLetMaxPrice.I tems.Insert(5, New ListItem("500", 500))
ddLetMaxPrice.I tems.Insert(6, New ListItem("600", 600))
ddLetMaxPrice.I tems.Insert(7, New ListItem("700", 700))
ddLetMaxPrice.I tems.Insert(8, New ListItem("800", 800))
ddLetMaxPrice.I tems.Insert(9, New ListItem("900", 900))
ddLetMaxPrice.I tems.Insert(10, New ListItem("1200" , 1200))
ddLetMaxPrice.I tems.Insert(11, New ListItem("1400" , 1400))
ddLetMaxPrice.I tems.Insert(12, New ListItem("1600" , 1600))
ddLetMaxPrice.I tems.Insert(13, New ListItem("1800" , 1800))
ddLetMaxPrice.I tems.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(999999999 999, 2000, 2500,
3000, 3500, 4000, 4500, 999999999999);

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

"I hear ma train a comin'
... hear freedom comin"

Nov 19 '05 #5
On Fri, 14 Oct 2005 Sc***********@e xcite.com <Sc***********@ excite.com> wrote:
You could try something like this:

Dim List() As String = {100, 200, 300, 400, 500, 600, 700}
DropDownList3.D ataSource = List
DropDownList3.D ataBind()
DropDownList3.I tems.Insert(0, New ListItem("No preference",
999999))
DropDownList3.I tems.Insert(Dro pDownList3.Item s.Count, New
ListItem("2000+ ", 999999))


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

"I hear ma train a comin'
.... hear freedom comin"
Nov 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
3006
by: Chris Cioffi | last post by:
I started writing this list because I wanted to have definite points to base a comparison on and as the starting point of writing something myself. After looking around, I think it would be a waste of time to start writing yet another IDE and so am now thinking in terms of new features/plug-ins for existing systems. Right now I mostly use Komodo Personal and it's pretty close to being what I want. They don't currently support plug-ins,...
92
6544
by: Reed L. O'Brien | last post by:
I see rotor was removed for 2.4 and the docs say use an AES module provided separately... Is there a standard module that works alike or an AES module that works alike but with better encryption? cheers, reed
30
3487
by: Reinhold Birkenfeld | last post by:
Hello, I know that there are different YAML engines for Python out there (Syck, PyYaml, more?). Which one do you use, and why? For those of you who don't know what YAML is: visit http://yaml.org/! You will be amazed, and never think of XML again. Well, almost.
137
7195
by: Philippe C. Martin | last post by:
I apologize in advance for launching this post but I might get enlightment somehow (PS: I am _very_ agnostic ;-). - 1) I do not consider my intelligence/education above average - 2) I am very pragmatic - 3) I usually move forward when I get the gut feeling I am correct - 4) Most likely because of 1), I usually do not manage to fully explain 3) when it comes true. - 5) I have developed for many years (>18) in many different environments,...
2
1299
by: Ross Clement (Email address invalid - do not use) | last post by:
Hi. I would like to make a typedef for a structure which can be joined up into a linked list. I include my code below. My code works, but I have a vague suspicion that I could have declared my "spectrum" type in a neater way. Is there a better way of doing the following? Thanks in anticipation, Ross-c #include <stdlib.h>
31
2595
by: Mason | last post by:
I've been working to become competent at making websites. My learning path has been: html -css- paintshop pro -javascript -php/mysql I'm getting somewhat proficient at php/mysql (although I have plenty to learn - I haven't even started on gd library) and want to think about my next step. Any suggestions?
8
1521
by: Shelly | last post by:
I get an error that the input string is not in the right format. Here is the result: Here is the partial code: Dim sqlConn As New SqlConnection(SqlDataSource1.ConnectionString) Dim query As String = "SELECT * FROM Agent WHERE accountNumber=" query += "@accountNumber AND agentID=@agentID AND authCode=@authCode" Dim sqlComm As New SqlCommand(query, sqlConn) sqlComm.Parameters.Add("@accountNumber", SqlDbType.Int).Value =...
6
1409
by: raphfrk | last post by:
While I am here, I just thought I'd ask if there is a recommended way of handling 2d dynamic arrays. I implement them using the following kind of code. ------------------------------------------------ int fname( int sizex, int sizey, <other inputs) {
5
1249
by: =?Utf-8?B?cm9kY2hhcg==?= | last post by:
hey all, i'm trying to capture only numeric keys and was wondering if there was a neater or compact way of writing the following snippet? thanks, rodchar private void LayOutMain_KeyDown(object sender, KeyEventArgs e) { switch (e.Key.ToString())
0
9515
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,...
1
10155
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
9995
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9029
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
5431
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...
0
5559
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4110
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
3718
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2916
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.