Repeater 套用
后台:s
/// <summary>
/// 加载事件
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>s
protected void Page_Load(object sender, EventArgs e)
{
if(!IsPostBack)
{
DataTable dt=new DataTable();
dt=selTable.seltable("select * from popedom where fatherid=0");
this.Repeater1.DataSource = dt;
this.Repeater1.DataBind();
}
}
protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater rep = e.Item.FindControl("Repeater2") as Repeater;//找到里层的repeater对象
DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项
int typeid = Convert.ToInt32(rowv["id"]); //获取填充子类的id
rep.DataSource = popedomManager.getPopedomByIds(typeid);
rep.DataBind();
}
}
前台:
<asp:Repeater ID="Repeater1" runat="server" OnItemDataBound="Repeater1_ItemDataBound">
<ItemTemplate>
<tr>
<td class="td_bg" height="23" style="text-align: center">
<%#Eval("name") %>
</td>
<td class="td_bg" height="23" width="90%">
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate>
<asp:CheckBox ID="CheckBox1" runat="server" />
<%#Eval("name") %>
</ItemTemplate>
</asp:Repeater>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>