473,385 Members | 1,569 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Understanding New on the List-object

I find it difficult to understand the difference between

Me.cmbChoose.Items.Add(New ListItem("hi"))
and
Me.cmbChoose.Items.Add("hi")

How will my application work different if I use one or another? Is one
of them more correct than the other?

Regards /Snedker
Jan 22 '07 #1
2 1027
They are just overloads.

the .Add("hi") will internally call the add (new ListItem("hi")).

It's just there for your convinience.

You would normally use the new ListItem when you also want to specify a
value, so you'd do new ListItem("Hi", "3");

One isn't better than the other.

Karl
--
http://www.openmymind.net/
http://www.fuelindustries.com/
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:48********************************@4ax.com...
>I find it difficult to understand the difference between

Me.cmbChoose.Items.Add(New ListItem("hi"))
and
Me.cmbChoose.Items.Add("hi")

How will my application work different if I use one or another? Is one
of them more correct than the other?

Regards /Snedker
Jan 22 '07 #2
"Morten Snedker" <morten_spammenot_ATdbconsult.dkwrote in message
news:48********************************@4ax.com...
>I find it difficult to understand the difference between

Me.cmbChoose.Items.Add(New ListItem("hi"))
and
Me.cmbChoose.Items.Add("hi")

How will my application work different if I use one or another? Is one
of them more correct than the other?
..NET supports the concept of method "overloading" - if you don't know what
that is, Google it...

In this case, the Add method of the Items collection of a DropDownList has
two overloads - one which requires a ListItem object and the other which
requires a string to be passed into it as an argument.

ASP.NET takes the DropDownList object and renders it as an HTML <select>
when it streams the markup down to the client.

When an Item is added to the Items collection by passing in a string,
ASP.NET renders an HTML <optionwhere the internal value and visible text
are the value of the string.

When an Item is added to the Items collection by passing a ListItem object,
ASP.NET renders an HTML <optionwhere the value is ListItem's value
property and the visible text is the ListItem's text property.

Once your page has been rendered to the browser, do a View Source and you'll
see the difference straightaway...
Jan 22 '07 #3

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

Similar topics

2
by: Max M | last post by:
I am using the fetch command from the imaplib to fetch messages. I get a result, but I am a bit uncertain as to how I should interpret it. The result is described at...
29
by: Brett | last post by:
I'd like to better understand how the following code works. I've posted questions below. namespace Something.Something1 { using System; public delegate void Test1(); public delegate void...
18
by: Simon | last post by:
Hi, I understand what one the differences between std::vector, std::deque and std::list is, the std::vector can have data inserted/deleted at the end. The std::deque can have data...
4
by: bitshadow | last post by:
I've been working on a link list implementation and I'm driving myself crazy trying to understand something. assuming i have a list and i have the following quasi pseudocode: add(list *head):...
1
by: JohnK | last post by:
I have a GridView MyClass List = new MyClass ; for (int i = 0; i < 10; i++) { List = new MyClass(); List.FirstName = " First " + i; List.LastName = " Last " + i; }
2
by: Greg Corradini | last post by:
Hello All, A few weeks ago, I wrote two scripts using mx.ODBC on an Access DB. Among other things, both scripts create new tables, perform a query and then populate the tables with data in a...
3
by: Greg Corradini | last post by:
Hello, I'm trying to perform a simple insert statement into a table called Parcel_Test (see code below). Yet, I get an error message that I've never seen before (see traceback below). I've tried...
3
by: Brad | last post by:
Hi folks, I'm still fairly new to programming in python and programming in general. A friend of mine is in a CompSci 101 course and was working on a slider game when he encountered a problem. We...
3
by: Tobiah | last post by:
list.append() will add the two element list as the next element of the list. list.extend() is equivalent to list = list + and the result is that each element of the added list becomes it's own...
3
by: PVACC | last post by:
I have a line of code thus: w3('<input type=radio name=rad onclick="parent.mySub('+i+')">'); The function w3() writes the code in an iframe. I need to set a variable "start" to the value "1"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.