#region Repeater绑定一级
public void Show()
{
sql = "select * from menus where parentId=0";
this.Repeater1.DataSource = ManageBLL.Sel(sql);
this.Repeater1.DataBind();
}
#endregion
#region Repeater绑定二级
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep2 = e.Item.FindControl("Repeater2") as Repeater;
DataRowView rowv = (DataRowView)e.Item.DataItem;
rep2.ItemDataBound += new RepeaterItemEventHandler(Repeater2_ItemDataBound); //最最重要的一句
int id = Convert.ToInt32(rowv["Id"]);
sql = "select * from menus where parentId = " + id.ToString();
rep2.DataSource = ManageBLL.Sel(sql);
rep2.DataBind();
}
}
#endregion
#region Repeater绑定二级
protected void Repeater2_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
//AlternatingItemTemplate,FooterTemplate,HeaderTemplate,ItemTemplate,SeparatorTemplate
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep3 = (Repeater)e.Item.FindControl("Repeater3");//找到里层的repeater对象
DataRowView rowvv = (DataRowView)e.Item.DataItem;
int id = Convert.ToInt32(rowvv["Id"]);
sql = "select * from menus where parentId = " + id.ToString();
rep3.DataSource = ManageBLL.Sel(sql);
rep3.DataBind();
}
}
#endregion