日期:2010-05-29 浏览次数:20482 次
(一).显示效果图
(二)代码
1.前台界面代码:
<%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="数据绑定控件同时显示主表和子表数据.WebForm1" %>
<%@ Import Namespace="System.Data" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
<HTML>
<HEAD>
<title>WebForm1</title>
<meta name="GENERATOR" Content="Microsoft Visual Studio .NET 7.1">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
</HEAD>
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<!-- 绑定主表数据 -->
<asp:repeater id="myRepeater" runat="server">
<HeaderTemplate>
<table border="0" bgcolor="lightblue">
</HeaderTemplate>
<ItemTemplate>
<tr>
<td style="background-color: lightgray">
<b>
<%# DataBinder.Eval(Container.DataItem,"TypeID") %>
<%# DataBinder.Eval(Container.DataItem,"TypeName") %>
</b>
<br>
<!-- 绑定子表数据 -->
<asp:repeater id="childRepeater" datasource='<%# ((DataRowView)Container.DataItem)
.Row.GetChildRows("TypeRelation") %>' runat="server">
<itemtemplate>
<table border="0" bgcolor="#ffcc33">
<tr>
<td>
<%# DataBinder.Eval(Container.DataItem,"[\"TypeID\"]") %>
<%# DataBinder.Eval(Container.DataItem, "[\"TypeDetail\"]")%>
<br>
</td>
</tr>
</table>
</itemtemplate>
</asp:repeater>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:repeater>
</form>
</body>
</HTML>
2. 后代代码
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
usin