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