473,396 Members | 1,816 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,396 software developers and data experts.

ListItemCollection Value in DropDownList - MIA!

Hi all --

I hate to yell "BUG", but can anyone explain why I cannot
get a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC
Nov 17 '05 #1
6 3358
I don't think you can databind to a listitem collection.

You would have to set the Items property to the collection you are
returning. If this property is not readonly, then you can go ahead and do
that.

Otherwise, with the current set up, you would have to loop through the
connection, and readd all the items to the actual dropdown.

"Kurt Mang" <sk****************@shaw.ca> wrote in message
news:00****************************@phx.gbl...
Hi all --

I hate to yell "BUG", but can anyone explain why I cannot
get a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC

Nov 17 '05 #2
I don't think you can databind to a listitem collection.

You would have to set the Items property to the collection you are
returning. If this property is not readonly, then you can go ahead and do
that.

Otherwise, with the current set up, you would have to loop through the
connection, and readd all the items to the actual dropdown.

"Kurt Mang" <sk****************@shaw.ca> wrote in message
news:00****************************@phx.gbl...
Hi all --

I hate to yell "BUG", but can anyone explain why I cannot
get a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC

Nov 17 '05 #3
OK, unbelievably this is what you have to do to get the
ListItemCollection to bind CORRECTLY to your data-bound
web control, assuming you want to include seperate Text &
Value properties:

With Me.ddlDest1Month
.DataSource = Me.ListMonths ' a ListItemCollection
.DataValueField = "Value"
.DataTextField = "Text"
.DataBind()
End With

.... there you have it. The control - be it a dropdown
list, checkbox list, etc. - doesn't recognise that the
default Value / Text properties shold be the
ListItemCollection's Value / Text properties. I LOVE
VB.NET, but I gotta say that's pretty dumb.

Kurt Mang
www.skyrocketsolutions.com
-----Original Message-----
Hi all --

I hate to yell "BUG", but can anyone explain why I cannotget a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC
.

Nov 17 '05 #4
OK, unbelievably this is what you have to do to get the
ListItemCollection to bind CORRECTLY to your data-bound
web control, assuming you want to include seperate Text &
Value properties:

With Me.ddlDest1Month
.DataSource = Me.ListMonths ' a ListItemCollection
.DataValueField = "Value"
.DataTextField = "Text"
.DataBind()
End With

.... there you have it. The control - be it a dropdown
list, checkbox list, etc. - doesn't recognise that the
default Value / Text properties shold be the
ListItemCollection's Value / Text properties. I LOVE
VB.NET, but I gotta say that's pretty dumb.

Kurt Mang
www.skyrocketsolutions.com
-----Original Message-----
Hi all --

I hate to yell "BUG", but can anyone explain why I cannotget a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC
.

Nov 17 '05 #5

It's not dumb - you can bind most controls to any
datasource by setting its DataSource property. The only
requirement is that DataSource be set to an object that
implements certain interface that allows enumeration, and
it doesn't care about specific type it's bound to. The
control needs to know which columns to read from, in your
case they are public properties of ListItem: "Value"
and "Text". If ListItem had a property called "Color" you
could bind to that as well. Makes sence now? My 2 cents
worth.

-----Original Message-----
OK, unbelievably this is what you have to do to get the
ListItemCollection to bind CORRECTLY to your data-bound
web control, assuming you want to include seperate Text &
Value properties:

With Me.ddlDest1Month
.DataSource = Me.ListMonths ' a ListItemCollection
.DataValueField = "Value"
.DataTextField = "Text"
.DataBind()
End With

.... there you have it. The control - be it a dropdown
list, checkbox list, etc. - doesn't recognise that the
default Value / Text properties shold be the
ListItemCollection's Value / Text properties. I LOVE
VB.NET, but I gotta say that's pretty dumb.

Kurt Mang
www.skyrocketsolutions.com
-----Original Message-----
Hi all --

I hate to yell "BUG", but can anyone explain why I

cannot
get a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC
.

.

Nov 17 '05 #6

It's not dumb - you can bind most controls to any
datasource by setting its DataSource property. The only
requirement is that DataSource be set to an object that
implements certain interface that allows enumeration, and
it doesn't care about specific type it's bound to. The
control needs to know which columns to read from, in your
case they are public properties of ListItem: "Value"
and "Text". If ListItem had a property called "Color" you
could bind to that as well. Makes sence now? My 2 cents
worth.

-----Original Message-----
OK, unbelievably this is what you have to do to get the
ListItemCollection to bind CORRECTLY to your data-bound
web control, assuming you want to include seperate Text &
Value properties:

With Me.ddlDest1Month
.DataSource = Me.ListMonths ' a ListItemCollection
.DataValueField = "Value"
.DataTextField = "Text"
.DataBind()
End With

.... there you have it. The control - be it a dropdown
list, checkbox list, etc. - doesn't recognise that the
default Value / Text properties shold be the
ListItemCollection's Value / Text properties. I LOVE
VB.NET, but I gotta say that's pretty dumb.

Kurt Mang
www.skyrocketsolutions.com
-----Original Message-----
Hi all --

I hate to yell "BUG", but can anyone explain why I

cannot
get a dropdown list / checkboxlist
to recognise the Value property of a ListItemCollection
(created at runtime) that I bind to it?

This is a simplified version of what I have. I see no
reason why this shouldn't work:

' Create the listitemcollection property:
Private ReadOnly Property ListMonths() As
ListItemCollection
Get
If Me._licMonths Is Nothing Then
Dim arrTemp As New
ListItemCollection
With arrTemp
.Add(New ListItem("Select
a month:", "00"))
.Add(New ListItem
("January", "01"))
.Add(New ListItem
("February", "02"))
.Add(New ListItem
("March", "03"))
.Add(New ListItem
("April", "04"))
.Add(New ListItem
("May", "05"))
.Add(New ListItem
("June", "06"))
.Add(New ListItem
("July", "07"))
.Add(New ListItem
("August", "08"))
.Add(New ListItem
("September", "09"))
.Add(New ListItem
("October", "10"))
.Add(New ListItem
("November", "11"))
.Add(New ListItem
("December", "12"))
End With
Me._licMonths = arrTemp
End If
Return Me._licMonths
End Get
End Property

' bind to a dropdown list: called in Page_Load
private sub PopulateDropDowns()
If Me.ddlDest1Month.Items.Count = 0 Then
With Me.ddlDest1Month
.DataSource = Me.ListMonths
.DataBind()
End With
End If
end sub
' the result (from view source of aspx page):
<select name="ucPreferences:ddlDest1Month"
id="ucPreferences_ddlDest1Month">
<option selected="selected" value="Select a
month:">Select a month:</option>
<option value="January">January</option>
<option value="February">February</option>
<option value="March">March</option>
<option value="April">April</option>
<option value="May">May</option>
<option value="June">June</option>
<option value="July">July</option>
<option value="August">August</option>
<option value="September">September</option>
<option value="October">October</option>
<option value="November">November</option>
<option value="December">December</option>

</select>

Aargh! Why aren't my values being sent to the control?

Thanks for any help / insight / workarounds. I don't
want to resort to checking the Text property rather than
the Value property.

Kurt Mang
Vancouver, BC
.

.

Nov 17 '05 #7

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

Similar topics

1
by: casey | last post by:
I am trying to bind a list collection with values to a radiobuttonlist, but when i try to access the selecteditem.value i always get the selecteditem.value private void Page_Load(object...
0
by: Gonçalo Boléo | last post by:
I'm creating a control that has a DropDownList in it. I wan't to expose in that control the ListItemCollection of the DropDown. I wan't that the exposed ListItemCollection appears in the Properties...
0
by: Kurt Mang | last post by:
Hi all -- I hate to yell "BUG", but can anyone explain why I cannot get a dropdown list / checkboxlist to recognise the Value property of a ListItemCollection (created at runtime) that I bind...
0
by: RAMADU | last post by:
Hi There is a ListItemCollection containing ListItems (of course), each of whose Value and Text properties have been set. The Value and Text's values are different i.e. ListItem.Text = "Name0"...
2
by: RAMADU | last post by:
Hi There is a ListItemCollection containing ListItems (of course), each of whose Value and Text properties have been set. The Value and Text's values are different i.e. ListItem.Text = "Name0"...
1
by: RichardH | last post by:
Hi, I have a ListItemCollection that I bind to DropDownList: ListItemCollection items = new ListItemCollection(); ListItem item; item = new ListItem("Option 1", "1"); items.Add(item); item =...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
0
by: John Smith | last post by:
This is what I am trying to do: <asp:datagrid id="DataGrid1" runat="server" AutoGenerateColumns="False"> <Columns> <asp:BoundColumn Visible="False" DataField="id" ReadOnly="True"...
1
by: john20 | last post by:
Hi All, I want to know how many items i can strore in ListitemCollection object. means what is the size of Listitemcollecation. i want to store 6000 item can i use LisitemCollection for later...
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: 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...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
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...
0
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,...

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.