//页面
<asp:Repeater ID="parentRepeater" runat="server">
<ItemTemplate>
<b>
<%# DataBinder.Eval(Container.DataItem, "CatelogName")%></b><br>
<asp:Repeater ID="childRepeater" runat="server" DataSource='<%# ((DataRowView)Container.DataItem)
.Row.GetChildRows("myrelation") %>'>
<HeaderTemplate>
<table>
<tr>
<th>
ProductName
</th>
<th>
ProductDescription
</th>
</tr>
</table>
</HeaderTemplate>
<ItemTemplate>
<%# DataBinder.Eval(Container.DataItem, "["ProductName"]")%>
<%# DataBinder.Eval(Container.DataItem, "["ProductDescription"]")%><br>
</ItemTemplate>
<FooterTemplate>
</FooterTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
//后台 .aspx.cs
DataSet ds = ProductDao.test();
ds.Relations.Add("myrelation", ds.Tables["Category"].Columns["CatelogID"],
ds.Tables["Product"].Columns["CatelogID"]);
parentRepeater.DataSource = ds.Tables["Category"];
Page.DataBind();
---------------------
//ProductDao.cs
public static DataSet test()
{
string connStr = @"Data Source=.;Initial Catalog=Test;Integrated Security=True";
string sql = @"select CatelogID, [CatelogName]
from [T_WAP_Product]
group by CatelogID,CatelogName";
DataSet ds = new DataSet();
SqlDataAdapter sqlAdapter = new SqlDataAdapter();
using (SqlConnection connection = new SqlConnection(connStr))
{
//前后两次填充dateset
sqlAdapter.SelectCommand = new SqlCommand(sql, connection);
sqlAdapter.Fill(ds, "Category");
sql = @"select *
FROM dbo.T_WAP_Product";
sqlAdapter.SelectCommand = new SqlCommand(sql, connection);
sqlAdapter.Fill(ds, "Product");
return ds;
}
}