473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

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 1370
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

6
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...
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...
3
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...
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...
6
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...
2
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. ...
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: 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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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...
0
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...
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,...

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.