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)("MyColumnName") %>
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).GetParentRow("RelationX")("Coo
lFieldName") %>
Great Huh! (yeah...I need a life)
Allen Davis said:
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?