http://www.cnblogs.com/zhang9418hn/archive/2011/05/05/2038082.html
<asp:Repeater ID="rpt1" runat="server" onitemdatabound="rpt1_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblzyc" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label>
<h1 onClick="javascript:ShowMenu(this,'NO0')"><%#Eval("name") %></h1>
<span id="NO0" class="no">
<asp:Repeater ID="rpt2" runat="server" onitemdatabound="rpt2_ItemDataBound">
<ItemTemplate>
<asp:Label ID="lblzyc1" runat="server" Text='<%#Eval("id") %>' Visible="false"></asp:Label>
<h2 onClick="javascript:ShowMenu(this,'NO00')"></h2>
<div style=" margin-top:-15px; margin-left:20px"> <a href='product.aspx?id=<%#Eval("id") %>'><%#Eval("name") %></a></div>
</table>
<ul id="NO00" class="no">
<asp:Repeater ID="rpt3" runat="server">
<ItemTemplate>
<li><a href='product.aspx?pid=<%#Eval("id") %>'><%#Eval("name") %></a></li>
</ItemTemplate>
</asp:Repeater>
</ul>
</ItemTemplate>
</asp:Repeater>
</span>
</ItemTemplate>
</asp:Repeater>
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
DataBind();
}
}
private void DataBind()
{
string sql = "select * from tclass where rootid=0";
DataTable dt = lisichuang.myDataAdapter(sql);
rpt1.DataSource = dt;
rpt1.DataBind();
}
protected void rpt1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater dataList = (Repeater)e.Item.FindControl("rpt2");
Label lbl = (Label)e.Item.FindControl("lblzyc");
int mainID = Convert.ToInt32(lbl.Text);
//this.Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + mainID.ToString() + "!')</script>");
if (mainID > 0)
{
//string sql = "select * from article";
string sql = "select * from tclass where rootid=" + mainID + " order by id asc";
DataTable dt = lisichuang.myDataAdapter(sql);
dataList.DataSource = dt;
dataList.DataBind();
}
}
}
protected void rpt2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater dataList = (Repeater)e.Item.FindControl("rpt3");
Label lbl = (Label)e.Item.FindControl("lblzyc1");
int mainID = Convert.ToInt32(lbl.Text);
//this.Page.ClientScript.RegisterStartupScript(GetType(), "", "<script>alert('" + mainID.ToString() + "!')</script>");
if (mainID > 0)
{
//string sql = "select * from article";
string sql = "select * from tclass where rootid=" + mainID + " order by id asc";
DataTable dt = lisichuang.myDataAdapter(sql);
dataList.DataSource = dt;
dataList.DataBind();
}
}
}