473,735 Members | 2,049 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cant bind Repeater to Custom Collection

Hi,

I have a custom collection class i wrote, LineItemsCollec tion, which is a
strongly typed collection of objects of my LineItem class.
The LineItem class is a simple class with just a couple properties, ProdID,
Description, Quantity and UPC. 3 strings and a long.
The LineItemsCollec tion class inherits from
System.Collecti ons.Specialized .NameObjectColl ectionBase.
It also implements both IEnumerable and IList.

I can bind a DataGrid to my collection with no problem. In the
ItemCreated/ItemDataBound, the value of e.Item.DataItem is properly returned
as a LineItem object. So i can do <%#
DataBinder.Eval (Container,"Dat aItem.Quantity" ) %> and get back a quantity.

However, if i try to bind to a Repeater, and i do the same thing, i get an
error "DataBinder.Eva l: 'System.String' does not contain a property with the
name Quantity." I had had this problem with the datagrid when i first made
my collection. After researching, i found out to inherit from IList, and it
fixed it. But apparently the Repeater does its databinding differently than
the DataGrid?

Can anyone explain what the Repeater needs differently than the Datagrid in
order to bind to a custom collection??

Thanks in advance,
- Arthur Dent.
Nov 18 '05 #1
2 2207
You might want to consider having your base class inherit from
CollectionBase which will give you all the necessary flexability (not to
mention allow you to bind to everything).

Also, try the following syntax in your repeater:

<%# ((LineItem)Cont ainer.DataItem) .Quantity %>
or in vb
<%# ctype(Container .DataItem, LineItem).Quant ity %>

not sure if it'll sovle the problem though....

you'll likely need to import the namespace of LineItem in your page with:
<%@ Import Namespace="Name spaceContainerL ineItem" %>

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"A Traveler" <hi************ *********@yahoo .com> wrote in message
news:OJ******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I have a custom collection class i wrote, LineItemsCollec tion, which is a
strongly typed collection of objects of my LineItem class.
The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long.
The LineItemsCollec tion class inherits from
System.Collecti ons.Specialized .NameObjectColl ectionBase.
It also implements both IEnumerable and IList.

I can bind a DataGrid to my collection with no problem. In the
ItemCreated/ItemDataBound, the value of e.Item.DataItem is properly returned as a LineItem object. So i can do <%#
DataBinder.Eval (Container,"Dat aItem.Quantity" ) %> and get back a quantity.

However, if i try to bind to a Repeater, and i do the same thing, i get an
error "DataBinder.Eva l: 'System.String' does not contain a property with the name Quantity." I had had this problem with the datagrid when i first made
my collection. After researching, i found out to inherit from IList, and it fixed it. But apparently the Repeater does its databinding differently than the DataGrid?

Can anyone explain what the Repeater needs differently than the Datagrid in order to bind to a custom collection??

Thanks in advance,
- Arthur Dent.

Nov 18 '05 #2
Yeah, that worked. I changed it to CollectionBase instead of
NameObjectColle ctionBase, and that apparently fixed it. Im not quite sure
why though, because if i look at all the interfaces and bases in the
objectbrowser, its all the same. At any rate it works now.

I didnt want to do a hard-coded cast in the repeater code simply to keep it
generic and usable for other collection types.

Thanks.
"Karl Seguin" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:ef******** ******@TK2MSFTN GP10.phx.gbl...
You might want to consider having your base class inherit from
CollectionBase which will give you all the necessary flexability (not to
mention allow you to bind to everything).

Also, try the following syntax in your repeater:

<%# ((LineItem)Cont ainer.DataItem) .Quantity %>
or in vb
<%# ctype(Container .DataItem, LineItem).Quant ity %>

not sure if it'll sovle the problem though....

you'll likely need to import the namespace of LineItem in your page with:
<%@ Import Namespace="Name spaceContainerL ineItem" %>

Karl

--
MY ASP.Net tutorials
http://www.openmymind.net/
"A Traveler" <hi************ *********@yahoo .com> wrote in message
news:OJ******** ******@TK2MSFTN GP11.phx.gbl...
Hi,

I have a custom collection class i wrote, LineItemsCollec tion, which is a
strongly typed collection of objects of my LineItem class.
The LineItem class is a simple class with just a couple properties,

ProdID,
Description, Quantity and UPC. 3 strings and a long.
The LineItemsCollec tion class inherits from
System.Collecti ons.Specialized .NameObjectColl ectionBase.
It also implements both IEnumerable and IList.

I can bind a DataGrid to my collection with no problem. In the
ItemCreated/ItemDataBound, the value of e.Item.DataItem is properly

returned
as a LineItem object. So i can do <%#
DataBinder.Eval (Container,"Dat aItem.Quantity" ) %> and get back a
quantity.

However, if i try to bind to a Repeater, and i do the same thing, i get
an
error "DataBinder.Eva l: 'System.String' does not contain a property with

the
name Quantity." I had had this problem with the datagrid when i first
made
my collection. After researching, i found out to inherit from IList, and

it
fixed it. But apparently the Repeater does its databinding differently

than
the DataGrid?

Can anyone explain what the Repeater needs differently than the Datagrid

in
order to bind to a custom collection??

Thanks in advance,
- Arthur Dent.


Nov 18 '05 #3

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

Similar topics

3
2737
by: anon | last post by:
I am having a hard time with makeing what I am trying to do work. I am making a questionaire web app. I have a custom control that has a label and 5 radio buttons. My problem is that each different topic for the questionaire is in a database and each questionaire will have a different number of questions. I am trying to use a repeater to creat multiple copies of the control, unfortunately when I do this the different controls act like...
2
2098
by: Pete Nelson | last post by:
Does anyone know of a way to bind a string collection to a datagrid? Basically, I have an object, CreditPlans, and a string collection, ModelNumbers. I'd like to bind the ModelNumbers collection to the datagrid, but because there isn't a custom object with properties, just a string object, I'm not sure how to reference it in the datagrid. FYI, I can enumerate through the collection... foreach(string modelNum in...
3
2862
by: WebMatrix | last post by:
I am struggling with implementing somewhat complicated UI web-control. I explored Repeater, but I am not sure if it's the best way to go. I am leaning towards writing my own custom control and creating elements on the fly dynamically. I have a control that needs to display 3 columns and n number of rows depending on number of records. Sounds simple. But each Row has a control with its own data source binding and value must be selected...
1
2014
by: Jack | last post by:
I have a repeater bound to a collection of business objects: ScoresRepeater.DataSource = objReferralTestScore.TestScore; ScoresRepeater.DataBind(); How can I add a "new" row to the repeater without adding to the collection of bus objects? Thanks in advance, Jack.
7
5486
by: charliewest | last post by:
Hello - I'm using a Repeater control to render information in a very customized grid-like table. The Repeater control is binded to a DataSet with several records of information. Within the Repeater control, I've placed DropDownLists and CheckBoxes. When the user has updated the information, he/he clicks the submit button which is outside the scope of the Repeater control.
1
15032
by: Mike Hofer | last post by:
I am trying to do something a little nonstandard, and am having some difficulty determining (a) if it can be done and (b) if so, how to do it. What I want to do is fill a dropdown combobox with data from a collection. Then, I want to bind that list to a member of a custom class. (Don't ask why, just trust me on that one. <gr>). What I'm doing now is binding the combo box to a collection, as follows: Dim items As ArmorTypeCollection =...
2
1347
by: A Traveler | last post by:
Hi, I have a custom collection class i wrote, LineItemsCollection, which is a strongly typed collection of objects of my LineItem class. The LineItem class is a simple class with just a couple properties, ProdID, Description, Quantity and UPC. 3 strings and a long. The LineItemsCollection class inherits from System.Collections.Specialized.NameObjectCollectionBase. It also implements both IEnumerable and IList.
5
1396
by: Jaybuffet | last post by:
a custom object. Similar to how I bind a collection of objects to a repeater. Is there a way to bind a single object to a Table? I could use a repeater, but seems over kill for a single object. Thanks for any help.
0
1355
by: sean worlock | last post by:
Hello all, I have googled like crazy for this with no sucess! I have a dataset containing a table with the following fields Table===Widths --------------------------------------------- WidthID---int (primary key) Width------decimal
0
8964
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9466
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9327
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9253
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9201
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8202
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6747
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6049
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4564
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

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.