我这里有个主从表例子,但不是查询出来的,点主表显示从表详细,具体LZ若需要,请发CSDN消息给我提供发联系方式,我把具体代码和数据库发给你
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>演示在Web页中使用GridView控件显示主从关系数据表</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <asp:Label ID="Label1" runat="server" Text="简体中文Office 2000罗斯文数据库客户表:" Width="413px"></asp:Label>
        <asp:Panel ID="Panel1" runat="server" Height="113px" Width="416px" ScrollBars="Both">
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" BackColor="White"
                BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
                DataKeyNames="客户ID" DataSourceID="AccessDataSource1" GridLines="None" Width="529px">
                <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                <Columns>
                    <asp:CommandField HeaderText="选择" ShowSelectButton="True" />
                    <asp:BoundField DataField="客户ID" HeaderText="客户ID" ReadOnly="True" SortExpression="客户ID" />
                    <asp:BoundField DataField="公司名称" HeaderText="公司名称" SortExpression="公司名称" />
                    <asp:BoundField DataField="地址" HeaderText="地址" SortExpression="地址" />
                    <asp:BoundField DataField="城市" HeaderText="城市" SortExpression="城市" />
                </Columns>
                <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            </asp:GridView>
        </asp:Panel>
    
    </div>
        <asp:Label ID="Label2" runat="server" Text="简体中文Office 2000罗斯文数据库订单表(当前选择客户):"></asp:Label>
        <asp:Panel ID="Panel2" runat="server" Height="124px" Width="417px" ScrollBars="Both">
            <asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" BackColor="White"
                BorderColor="White" BorderStyle="Ridge" BorderWidth="2px" CellPadding="3" CellSpacing="1"
                DataKeyNames="订单ID" DataSourceID="AccessDataSource2" GridLines="None" Width="463px">
                <FooterStyle BackColor="#C6C3C6" ForeColor="Black" />
                <Columns>
                    <asp:BoundField DataField="订单ID" HeaderText="订单ID" InsertVisible="False" ReadOnly="True"
                        SortExpression="订单ID" />
                    <asp:BoundField DataField="客户ID" HeaderText="客户ID" SortExpression="客户ID" />
                    <asp:BoundField DataField="运货商" HeaderText="运货商" SortExpression="运货商" />
                    <asp:BoundField DataField="运货费" HeaderText="运货费" SortExpression="运货费" />
                </Columns>
                <RowStyle BackColor="#DEDFDE" ForeColor="Black" />
                <SelectedRowStyle BackColor="#9471DE" Font-Bold="True" ForeColor="White" />
                <PagerStyle BackColor="#C6C3C6" ForeColor="Black" HorizontalAlign="Right" />
                <HeaderStyle BackColor="#4A3C8C" Font-Bold="True" ForeColor="#E7E7FF" />
            </asp:GridView>
        </asp:Panel>
        <asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/Northwind.mdb"
            SelectCommand="SELECT DISTINCT [客户ID], [公司名称], [地址], [城市] FROM [客户]">
        </asp:AccessDataSource>
        <asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/Northwind.mdb"
            SelectCommand="SELECT [订单ID], [客户ID], [运货商], [运货费] FROM [订单] WHERE ([客户ID] = ?)">
            <SelectParameters>
                <asp:ControlParameter ControlID="GridView1" Name="客户ID" PropertyName="SelectedValue"
                    Type="String" />
            </SelectParameters>
        </asp:AccessDataSource>
    </form>
</body>
</html>

解决方案 »

  1.   

    我是想独立布局!主表和从表的DataView我想做成自己想要的表格格式。
      

  2.   

    感谢各位的赐教!用DataView和DetailsView组合来显示主从表。但是我现在还有问题,想请教各位,我想DataView和DetailsView来显示数据的时候,不喜欢他默认的表格方式,我想我自己设计的表格布局,不知道该如何做????
      

  3.   

    无论是否用自己设计的表格都可以用CSS控制样式