473,699 Members | 2,219 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 937
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

11
2196
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 least-recently-used objects?
15
2467
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 to acomplish the same functionality in asp.net.
11
3831
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 ways to do this through prototyping and other techniques, but these behaviors need to be static and...
3
1383
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 DataField property of the BoundColum, as below: <asp:BoundColumn Visible="False"...
0
8620
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 synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9180
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
9038
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
8920
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
7755
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
6536
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
4633
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3060
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2351
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.