Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   ASP .Net (http://www.velocityreviews.com/forums/f29-asp-net.html)
-   -   what's a neater way of writing this simple code... (http://www.velocityreviews.com/forums/t111640-whats-a-neater-way-of-writing-this-simple-code.html)

Stimp 10-14-2005 01:45 PM

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.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?
--

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

ScottStoecker@excite.com 10-14-2005 02:13 PM

Re: what's a neater way of writing this simple code...
 
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.Cou nt, New
ListItem("2000+", 999999))

Hope that helps,
Scott


parez 10-14-2005 02:19 PM

Re: what's a neater way of writing this simple code...
 
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.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?
> --
>
> "I hear ma train a comin'
> ... hear freedom comin"



Stimp 10-14-2005 02:26 PM

Re: what's a neater way of writing this simple code...
 
Either.. I'm working in VB, but can translate from C# :)

On Fri, 14 Oct 2005 parez <psawant@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.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?
>> --
>>
>> "I hear ma train a comin'
>> ... hear freedom comin"

>



--

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

S. Justin Gengo 10-14-2005 02:31 PM

Re: what's a neater way of writing this simple code...
 
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" <ren@spumco.com> wrote in message
news:slrndkvdjt.al5.ren@carbon.redbrick.dcu.ie...
> 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?
> --
>
> "I hear ma train a comin'
> ... hear freedom comin"




Stimp 10-14-2005 03:03 PM

Re: what's a neater way of writing this simple code...
 
On Fri, 14 Oct 2005 ScottStoecker@excite.com <ScottStoecker@excite.com> wrote:
> 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.Cou nt, New
> ListItem("2000+", 999999))


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


--

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


All times are GMT. The time now is 09:30 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.