Use Parent Column in Child?

Discussion in 'ASP .Net Datagrid Control' started by Allen Davis, Apr 30, 2004.

  1. Allen Davis

    Allen Davis Guest

    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?
     
    Allen Davis, Apr 30, 2004
    #1
    1. Advertising

  2. Allen Davis

    David Jessee Guest

    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" <> wrote in message
    news:...
    > 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?
     
    David Jessee, May 1, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. davout
    Replies:
    0
    Views:
    571
    davout
    Apr 18, 2004
  2. Jeff Rodriguez
    Replies:
    23
    Views:
    1,181
    David Schwartz
    Dec 9, 2003
  3. Replies:
    0
    Views:
    221
  4. Noel Dolan
    Replies:
    0
    Views:
    261
    Noel Dolan
    Jul 18, 2004
  5. Bitswapper
    Replies:
    5
    Views:
    175
    Prasad, Ramit
    Aug 27, 2013
Loading...

Share This Page