473,569 Members | 3,043 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Refering to Object Members in A Collection in an ASP.NET BoundColu

I've created a number of business entities for an applciation I'm working on
in ASP.NET (Framework 1.1) and would like to quickly get data into a
BoundColumn for a control that consums a collection. Generally speaking,
when a databound control consums a collection, one simply sets the property
name of the collection members when setting the DataField property of the
BoundColum, as below:
<asp:BoundColum n Visible="False" DataField="ObjI d"
HeaderText="id" ></asp:BoundColumn >

So in the example above, the DataField "ObjId" is a property of a collection
member, we'll call "ObjectA" (i.e. ObjectA.ObjId") .

Now consider we want to do the same thing, but that one of ObjectA's
properties is another object called ObjectB (i.e. ObjectA.ObjectB ) which has
its own properties. Just to make things interesting, we'll say that ObjectA
and ObjectB inherit from the same parent class, and that ObjId is an abstract
integer property of that parent class. Thus ObjId is a property of both
ObjectA and ObjectB, and still that ObjectA has ObjectB as one of its
properties.

So as above, we want to refer to ObjectB.ObjId in our BoundColumn, but
unfortunately the collection being consumed is a collection of ObjectA's and
every time I try to refer to any of the properties of ObjectB (i.e.
ObjectA.ObjectB .ObjId) I get an exception being cast.

The question, then is - what syntax would I use in the .aspx file, within
the BoundColumn tag's DataField proeprty to set that property to retrieve
data from ObjectA.ObjectB .ObjId?

Very gratefully,

--
Ross Holder
Ottawa, ON (Canada)
http://spaces.msn.com/members/ross613
Mar 10 '06 #1
3 1378
Hi,

I have never used it in a boundcolumn but do it all the time with a
TemplateColumn , it's very easy you have to cast it to the correct type and
after that you can access the properties as needed.

Here goes an example:

<itemtemplate >
<span ><%# ((CtpRecord)Con tainer.DataItem ).DateRequested .ToString(
"MM/dd/yy", DateTimeFormatI nfo.InvariantIn fo) %></span>
</itemtemplate>
CtpRecord is a class and the grid is binded to a strong typed collection of
CtpRecords

DateRequestes is a DateTime property

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation
Mar 10 '06 #2

This may or may not help.

While I do most of my development in asp.net, and not winforms, what you're
asking I only have a winforms snipplet.

Me.txtPubId.Dat aBindings.Add(N ew Binding("Text", Me.m_model,
"CurrentPublish er.PublisherId" ))

m_model is a business object. Its actually reflects a title from the pubs
database.

One of the the things a title has, is a publisher.

class Tittle
public Publisher CurrentPublishe r
{get{return m_publisher;}}

class Publisher
public string PublisherId
thats the base line objects and properties.

Maybe that can help. My winfroms example works, but I haven't done alot of
MVC in asp.net to tell the truth. Esp with the WebControls.Dat aBind stuff.

.....

If you find an answer, please post it.

"Ross Holder" <Ro********@dis cussions.micros oft.com> wrote in message
news:28******** *************** ***********@mic rosoft.com...
I've created a number of business entities for an applciation I'm working on in ASP.NET (Framework 1.1) and would like to quickly get data into a
BoundColumn for a control that consums a collection. Generally speaking,
when a databound control consums a collection, one simply sets the property name of the collection members when setting the DataField property of the
BoundColum, as below:
<asp:BoundColum n Visible="False" DataField="ObjI d"
HeaderText="id" ></asp:BoundColumn >

So in the example above, the DataField "ObjId" is a property of a collection member, we'll call "ObjectA" (i.e. ObjectA.ObjId") .

Now consider we want to do the same thing, but that one of ObjectA's
properties is another object called ObjectB (i.e. ObjectA.ObjectB ) which has its own properties. Just to make things interesting, we'll say that ObjectA and ObjectB inherit from the same parent class, and that ObjId is an abstract integer property of that parent class. Thus ObjId is a property of both
ObjectA and ObjectB, and still that ObjectA has ObjectB as one of its
properties.

So as above, we want to refer to ObjectB.ObjId in our BoundColumn, but
unfortunately the collection being consumed is a collection of ObjectA's and every time I try to refer to any of the properties of ObjectB (i.e.
ObjectA.ObjectB .ObjId) I get an exception being cast.

The question, then is - what syntax would I use in the .aspx file, within
the BoundColumn tag's DataField proeprty to set that property to retrieve
data from ObjectA.ObjectB .ObjId?

Very gratefully,

--
Ross Holder
Ottawa, ON (Canada)
http://spaces.msn.com/members/ross613

Mar 10 '06 #3
"Ignacio Machin ( .NET/ C# MVP )" wrote:
Hi,

I have never used it in a boundcolumn but do it all the time with a
TemplateColumn , it's very easy you have to cast it to the correct type and
after that you can access the properties as needed.

Here goes an example:

<itemtemplate >
<span ><%# ((CtpRecord)Con tainer.DataItem ).DateRequested .ToString(
"MM/dd/yy", DateTimeFormatI nfo.InvariantIn fo) %></span>
</itemtemplate>


Ya know, I've gotta learn to do more complete research before posting to a
newsgroup. ;) In fact I'd found this exact solution in a CodeProject article
concernging databinding:
http://www.codeproject.com/aspnet/Ma...ataBinding.asp

Even so, the prompt assistance is greatly appreciated - as always!

Sincerely,

--
Ross Holder
Ottawa, ON (Canada)
http://spaces.msn.com/members/ross613
Mar 10 '06 #4

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

Similar topics

6
3303
by: Iain Bishop | last post by:
I'm trying to model objects for the following problem: A building site contains assemblies, each of which can contain other assemblies and/or materials. I have modelled this using a Site class, Assembly class, and Material class as follows... Site Class (clsSite): Option Explicit
11
2172
by: Vani Murarka | last post by:
Hi Everyone, Does .NET offer any collection class which will give me objects last *accessed* such that I may build a least-recently-used cache that kills off objects that haven't been used for awhile? Or is there any other way to implement this kind of a cache / collection where one can do this kind of cleanup based on...
3
2133
by: hellrazor | last post by:
Hi there, I'm trying to consume a web-service that is supposed to return a collection of a custom object. The web-service was not created with C# or VS.net. It was created with IBM VisualAge Smalltalk 6. I haven't had problems consuming other web-services but c# seems to choke with "Collection" return types. If you'd like to try to see...
15
2456
by: randyr | last post by:
I am developing an asp.net app based on a previous asp application. in the asp applications global.asa file I had several <object id="id" runat="server" scope="scope" class="comclass"> tags for objects that the app used to speed up some global level data access and functionality. I have recoded the class libraries in .net and would like...
6
1613
by: Gary Frank | last post by:
What are the ramifications if I were to instantiate an object tens of thousands of times and add them to an array? Or hundreds of thousands of times? Do you know if the act of instantiating a class takes a lot of storage or other resources? Would it be a severe performance penalty? From the .Net help doc:
2
3188
by: bughunter | last post by:
This is partly 'for the record' and partly a query about whether the following is a bug somewhere in .Net (whether it be the CLR, JITter, C# compiler). This is all in the context of .Net 1.1 SP1. Recently we (my fellow team members & I) observed an InvalidOperationException - 'collection has been modified', however it wasn't immediately...
11
3810
by: Kevin Prichard | last post by:
Hi all, I've recently been following the object-oriented techiques discussed here and have been testing them for use in a web application. There is problem that I'd like to discuss with you experts. I would like to produce Javascript classes that can be "subclassed" with certain behaviors defined at subclass time. There are plenty of...
3
1347
by: RSH | last post by:
I am slowly getting the hang of objects and creating my own. I was given some help in assigning an object to a ComboBox collection. I have been looking at it and I get the concept which is very powerful but I'm having a bit of a problem conceptually. I was hoping someone might be able to shed some light on creating this object and assigning...
3
935
by: Ross Holder | last post by:
I've created a number of business entities for an applciation I'm working on in ASP.NET (Framework 1.1) and would like to quickly get data into a BoundColumn for a control that consums a collection. Generally speaking, when a databound control consums a collection, one simply sets the property name of the collection members when setting the...
0
7703
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...
0
7619
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7930
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. ...
1
7681
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...
0
7983
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...
0
6290
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...
1
5514
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...
0
3651
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1229
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.