protected void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
Repeater repeater2 = e.Item.FindControl("Repeater2") as Repeater;
if (repeater2 != null)
{
repeater2.DataSource = 数据源;
repeater2.DataBind();
}
}
}
页面代码:
<asp:Repeater ID="Repeater1" runat="server">
<ItemTemplate>
<asp:Repeater ID="Repeater2" runat="server" DataSource='<%#BackDataSourse(Eval("关联字段值").ToString())%>'>
<ItemTemplate>
<%#Eval("遍历内容列")%>
</ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
后台代码:
1.先绑定Repeater1控件
2.返回绑定Repeater2r控件的数据源
public DataTable BackDataSourse(string ColumnValue)
{
DataTable datasourse = new DataTable();
//绑定数据表
return datasourse;
}
这不就OK了
if (!IsPostBack)
{
Repeater1.DataSource = categoryBLL.selectCategoryAll();
Repeater1.DataBind();
for (int i = 0; i < Repeater1.Items.Count; i++)
{
Label la = (Label)Repeater1.Items[i].FindControl("Label1");
int ID = Convert.ToInt32(la.Text);
Repeater re = (Repeater)Repeater1.Items[i].FindControl("Repeater2");
re.DataSource = seriesBLL.selectSeriesAll(ID);
re.DataBind();
}
}
在对应页面中的pageload事件中写