CheckBoxList and custom typesafe collection woes

M

Matthias S.

Hi there,

I have a typesafe collection in my application called Countries, which
is derived from the ReadOnlyCollectionBase. As you might guess, the
item-value is of type Country. Each Country has (for now) and ID and a
Name property.

Now I'd like to use a CheckBoxList to display the contents of my
Countries collection and let the user select some:

// chklCountries is the CheckBoxList
Countries colCountries = new Countries();
chklCountries.DataSource = colCountries;
chklCountries.DataTextField = "Name"; // Country.Name?
chklCountries.DataValueField = "ID"; // Country.ID?
chklCountries.DataBind();

There are no countries loaded at runtime eventhough the collection works
correctly. The HTML output is a funny:

<table id="chklCountries" border="0">
</table>

That's it. What am I missing?
 
J

JV

It's hard to tell from that snippet, but:
(1) It looks like you created an array but didn't add any items to the
array. maybe you left that out or it's hidden in the collection's
implemenation?
(2) does your Country class contain public properties or just public
member variables?
 
K

Karl Seguin

Agreed..but wanted to specifically point out the "funny" output...a
checkboxlist gets rendered inside a table....unless you change the
RepeatLayout to "flow" in which case it gets rendered inside <span>...it's
an empty table because, as Jv pointed out, there are no records in the
collection.

Also, the reason you need properties vs fields is that it uses the
reflection GetProperty method...just an fyi..

karl

--
MY ASP.Net tutorials
http://www.openmymind.net/ - New and Improved (yes, the popup is
annoying)
http://www.openmymind.net/faq.aspx - unofficial newsgroup FAQ (more to
come!)
 
M

Matthias S.

I'm honestly sorry about it guys: It was me playing blind-fish. Yes, the
collection was actually empty ;(

/Matthias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top