473,468 Members | 1,294 Online
Bytes | Software Development & Data Engineering Community
Create 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:BoundColumn Visible="False" DataField="ObjId"
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 930
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)Container.DataItem).DateRequested.ToSt ring(
"MM/dd/yy", DateTimeFormatInfo.InvariantInfo) %></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.DataBindings.Add(New Binding("Text", Me.m_model,
"CurrentPublisher.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 CurrentPublisher
{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.DataBind stuff.

.....

If you find an answer, please post it.

"Ross Holder" <Ro********@discussions.microsoft.com> wrote in message
news:28**********************************@microsof t.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:BoundColumn Visible="False" DataField="ObjId"
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)Container.DataItem).DateRequested.ToSt ring(
"MM/dd/yy", DateTimeFormatInfo.InvariantInfo) %></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
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...
15
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...
11
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...
3
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...
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
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...
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,...
1
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.