日期:2014-05-18  浏览次数:20503 次

GridView如何做主子表?
GridView如何做主子表?

我想把主表信息和子表信息都在一个GridView显示怎么做啊,求大虾帮忙!!!!!
给个思路,或者发段代码看下。
谢谢了!!!

------解决方案--------------------
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GridView_GirdView.aspx.cs" Inherits="GridSamples_GridView_GirdView" %>
 
 <!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>无标题页</title>
 </head>
 <body>
<form id="form1" runat="server">
<div>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="deptid"
DataSourceID="AccessDataSource1" AllowPaging="True" AllowSorting="True" PageSize="2" OnRowDataBound="GridView1_RowDataBound">
<Columns>
<asp:BoundField DataField="deptid" HeaderText="部门编号" InsertVisible="False" ReadOnly="True"
SortExpression="deptid" />
<asp:BoundField DataField="deptname" HeaderText="部门名称" SortExpression="deptname" />
<asp:BoundField DataField="deptremark" HeaderText="备注" SortExpression="deptremark" />
<asp:TemplateField HeaderText="人员信息">
<ItemTemplate>
<asp:GridView ID="GridView2" runat="server" AutoGenerateColumns="False" DataKeyNames="id"
DataSourceID="AccessDataSource2" AllowPaging="True" AllowSorting="True" PageSize="5">
<Columns>
<asp:BoundField DataField="id" HeaderText="人员编号" InsertVisible="False" ReadOnly="True"
SortExpression="id" />
<asp:BoundField DataField="name" HeaderText="姓名" SortExpression="name" />
<asp:BoundField DataField="sex" HeaderText="性别" SortExpression="sex" />
</Columns>
<PagerSettings FirstPageText="首页" LastPageText="末页" Mode="NextPreviousFirstLast"
NextPageText="下一页" PreviousPageText="上一页" />
</asp:GridView>
<asp:AccessDataSource ID="AccessDataSource2" runat="server" DataFile="~/App_Data/test.mdb"
SelectCommand="SELECT [id], [name], [sex], [deptid] FROM [employees] WHERE ([deptid] = ?)">
<SelectParameters>
<asp:Parameter Name="deptid" Type="Int32" />
</SelectParameters>
</asp:AccessDataSource><br>
</ItemTemplate>
</asp:TemplateField>

</Columns>
<PagerSettings FirstPageText="首页" LastPageText="末页"
NextPageText="下一页" PreviousPageTe