原文发布时间为:2009-05-21 —— 来源于本人的百度文章 [由搬家工具导入]
DataRelation 实现父子表
if (!IsPostBack)
{
using (OleDbConnection con = new OleDbConnection(cn))
{
DataSet ds = new DataSet();
OleDbDataAdapter dr1 = new OleDbDataAdapter("select * from km", con);
OleDbDataAdapter dr2 = new OleDbDataAdapter("select * from km1", con);
dr1.Fill(ds, "tb1");
dr2.Fill(ds, "tb2");
ds.Relations.Add("newtb", ds.Tables[0].Columns["id"], ds.Tables[1].Columns["flag"]);
Repeater1.DataSource = ds;
Repeater1.DataBind();
}
}
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<div class="adminleft" id='admin<%# Eval("id") %>'>
<h2 id='h<%# Eval("id") %>' onmouseout="fff('h<%# Eval("id") %>')" onmouseover="f('h<%# Eval("id") %>')" onclick="javascript:location.href='showbj.aspx?flag=<%# Eval("id") %>&na=<%# Eval("subject") %>'"><%#Eval("subject") %></h2>
<ul>
<asp:Repeater ID="Repeater2" runat="server" DataSource='<%# ((DataRowView)Container.DataItem).Row.GetChildRows("newtb") %>' OnItemCommand="Repeater1_ItemCommand">
<ItemTemplate>
<li><asp:LinkButton ID="LinkButton1" runat="server" CommandArgument='<%#Eval("["flag"]") %>' CommandName="re"><%#Eval("["subject"]") %></asp:LinkButton></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</div>
</ItemTemplate>
</asp:Repeater>