views:

1800

answers:

2

Hi,

I have a parent table called Publication and a child table called Owner. These two (data)tables are contained within a DataSet (this is all C# stuff) and have a defined relationship. One publication can have more than one owner.

I am using a GridView control and my question is, how do I get the information in the child table to show up in the gridview control? The gridview is linked to the main dataset.

I have read the information here, but what's annoying is that writing stuff to the console isn't very useful!

http://msdn.microsoft.com/en-us/library/d6s958d6(VS.80).aspx

Thanks R.

+1  A: 

Are you wanting the child information to overwirte what is in the parent grid, show up as nested rows under the parent row, or the easiest way, show another grid below that grid and then on selection of the parent grid row, populate the bottom grid with the subset information?

Take a look at http://www.asp.net/learn/data-access/tutorial-10-cs.aspx

Instead of sticking the info in the details view, just use another gridview. Clarify your desired output and I can perhaps point you in a better direction.

UPDATE: I believe this article which has detailed code will give you exactly what you are looking for, although there might be an easier way or a more elegant solution, this will at least get you up and running for now.

http://www.aspboy.com/Categories/GridArticles/Hierarchical%5FGridView%5FWith%5FClickable%5FRows.aspx

Breadtruck
Thanks Breadtruck, What I am trying to do is get the list of owners to show up in a cell in the parent gridview, so something like Publication, City, State, Type, Owners Brocks View Oklahom OK W News Press Some big corp We own everything ltd. Some other publicationI hope that clarifies it a bit.
flavour404
And of course my formatting of that comment was completely lost!The owners should show up as a list.
flavour404
A: 

Well if you want it in the same gridview, you have to display it in a column... how about a template field in the columns collection which on databinding calls some code that looks up the child records based on the id of the Publication:

<Columns>

        <asp:TemplateField HeaderText="Description" SortExpression="Description">
            <ItemTemplate>
      <%# GetChildRowRepresentation((int)Eval("Id")) %>
            </ItemTemplate>
        </asp:TemplateField> 

</Columns>



protected string GetChildRowRepresentation(int id)
{
    //look up the data set, return the appropriate info
}

A repeater might be a better decision than a gridview as they are friendlier for using custom layouts.

CRice