Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Use Parent Column in Child?

Reply
Thread Tools

Use Parent Column in Child?

 
 
Allen Davis
Guest
Posts: n/a
 
      04-30-2004
Is there a way to retrieve a column from the parent table of a relationship and display it in the child data control? In my case, I'd like to show a column from the parent DataList showing seating capacity in the child DataList's ItemTemplate. Is this possible?
 
Reply With Quote
 
 
 
 
David Jessee
Guest
Posts: n/a
 
      05-01-2004
If you're binding to a dataSet with the relations defined inside of it, then
yes.

You'll notice that all of these databinding Expressions that you see refer
to DataItem
If you look into your object Browser for the definition of
System.Web.UI.WebControls.DataGridItem.DataItem you'll notice that type for
this property is Object. This is because you can databind to all sorts of
things. In your case, you're binding your DataList to a DataTable, which is
a collection of DataRows. Therefore you know that the DataItem that you're
Container is giving you in these binding Expressions is a DataRow.

so you could create a binding Expression that looks like
<%# ctype(Container.DataItem,System.Data.DataRow)("MyC olumnName") %>
to get a column to output.

now here's where it gets neat......
since you can get a reference to the DataItem, and cast it to a particulat
Type, you have access to all of the properties/Methods Exposed by that type!

so if you know that your datatable has a parent relation called "RelationX"
and the parent table has a field called "CoolFieldName" you could access
that value like so:
<%#
ctype(Container.DataItem,System.Data.DataRow).GetP arentRow("RelationX")("Coo
lFieldName") %>

Great Huh! (yeah...I need a life)




"Allen Davis" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Is there a way to retrieve a column from the parent table of a

relationship and display it in the child data control? In my case, I'd like
to show a column from the parent DataList showing seating capacity in the
child DataList's ItemTemplate. Is this possible?


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
If a class Child inherits from Parent, how to implementChild.some_method if Parent.some_method() returns Parent instance ? metal Python 8 10-30-2009 10:31 AM
Page load of the parent page called twice when a modal dialog is opened from a button click of the user control on the parent page Samy ASP .Net 2 08-15-2005 03:30 PM
Parent - Child back to parent javascript thingybob mark ASP .Net 1 03-10-2005 02:20 PM
What does sender.Parent.Parent.Cells() reference? Frustrating... Roy ASP .Net 2 02-11-2005 09:00 PM
Getting a page to refresh the parent, even when not loaded from the parent? Bill S. Javascript 2 05-08-2004 04:56 AM



Advertisments