J
Jonathan Wood
I was trying to populate a DropDownList control and started by trying the
following code:
Dim i As Integer
Dim li As ListItem = New ListItem
For i = 1 To 50
li.Value = i.ToString()
li.Text = "This is item " + i.ToString()
DropDownList1.Items.Add(li)
Next i
Now, while I'm new to .NET, I've been programming many years and was able to
quickly find another way to make this work.
So I'm not looking for a workaround, but I would like someone to help me
understand why the above code does what it does. What it does is result in
every item in the list with the text "This is item 50". Obviously, the
control saves an object for each item and changes to those items are
reflected in the list. But why is it done this way? Isn't this horribly
inefficent?
Jonathan
following code:
Dim i As Integer
Dim li As ListItem = New ListItem
For i = 1 To 50
li.Value = i.ToString()
li.Text = "This is item " + i.ToString()
DropDownList1.Items.Add(li)
Next i
Now, while I'm new to .NET, I've been programming many years and was able to
quickly find another way to make this work.
So I'm not looking for a workaround, but I would like someone to help me
understand why the above code does what it does. What it does is result in
every item in the list with the text "This is item 50". Obviously, the
control saves an object for each item and changes to those items are
reflected in the list. But why is it done this way? Isn't this horribly
inefficent?
Jonathan