前台
<asp:Repeater id="rpt" runat="server">
<ItemTemplate>
<tr>
<td width="41" align="center">></td>
<td width="98" align="center"><%# DataBinder.Eval(Container.DataItem,"powername") %></td>
<td width="414" align="left">
<table width="85" height="25" border="0" cellpadding="0" cellspacing="0">
<tr>
<asp:Repeater id="subrpt" runat="server">
<ItemTemplate>
<td align="center"><%# DataBinder.Eval(Container.DataItem,"powername") %></td>
</ItemTemplate>
</asp:Repeater></tr>
</table>
</td>
<td width="47" align="center">更多</td>
</tr>
</ItemTemplate>
</asp:Repeater>
</table>
后台
using System;
using System.Data;
using System.Drawing;
using System.Data.SqlClient;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
/// <summary>
/// ShowAll 的摘要说明。
/// </summary>
public class ShowAll : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.Repeater subrpt;
protected System.Web.UI.WebControls.Repeater rpt;
public string CategoryID="0";
public string WebCount="4";
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面
if(!this.IsPostBack)
{
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlDataAdapter cmd1=new SqlDataAdapter("select powername,id from navigationsort where parentid="+CategoryID+" order by orderid desc",con);
DataSet ds=new DataSet();
cmd1.Fill(ds,"pt");
rpt.DataSource=ds.Tables["pt"];
rpt.DataBind();
con.Close();
}
}
private void rpt_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater subrpt = (Repeater) e.Item.FindControl("subrpt");
DataRowView rowv = (DataRowView)e.Item.DataItem;
string ParentId = rowv["id"].ToString();
subrpt.DataSource=getsub(ParentId);
subrpt.DataBind();
}
}
private DataSet getsub(string id)
{
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"]);
SqlDataAdapter cmd1=new SqlDataAdapter("select top "+WebCount+" title,id from navigation where sortid="+id,con);
DataSet ds=new DataSet();
cmd1.Fill(ds);
con.Close();
return ds;
}
}