repeater嵌套问题...
页面代码:<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Repeater ID="Repeater1" runat="server" OnItemCommand="Repeater1_ItemCommand">
<HeaderTemplate></HeaderTemplate>
<ItemTemplate><div>
<asp:Label ID="Label1" runat="server" Text='<%# Eval("name") %>'></asp:Label></div>
<asp:Repeater ID="Repeater2" runat="server">
<ItemTemplate><div><%# Eval("name") %></div></ItemTemplate>
</asp:Repeater>
</ItemTemplate>
</asp:Repeater>
</div>
</form>
</body>
</html>
我把Repeater1和Repeater2设置了同一个DataSet
调试页面的时候会出现.当前上下文中不存在名称Repeater2,当我把Repeater2从Repeater1中拿出来后.就能正常.有谁知道为什么吗?
--------------------编程问答-------------------- 按如下方式对 Repeater2进行数据绑定即可:
foreach (RepeaterItem item in Repeater1.Items)
{
Repeater r2 = (Repeater)item.FindControl("Repeater2");
r2.DataSource = dt;
r2.DataBind();
} --------------------编程问答-------------------- 为什么不能直接
Repeater1.DataSource=dt;
Repeater1.DataBind();
Repeater2.DataSource=dt;
Repeater2.DataBind(); --------------------编程问答-------------------- 你要把子repeater拿出来才行.
一般在itemdatabound事件中
Repeater Repeater2;
if (e.Item.ItemType == ListItemType.AlternatingItem || e.Item.ItemType == ListItemType.Item)
{
Repeater2= (Repeater)e.Item.FindControl("Repeater2");
Repeater2.DataSource=...
Repeater2.DataBound();...........
} --------------------编程问答-------------------- 为什么不能直接
Repeater1.DataSource=dt;
Repeater1.DataBind();
Repeater2.DataSource=dt;
Repeater2.DataBind();
-----------------------------
嵌套之后,页面里边就不止一个Repeater2了吧
所以子Repeater的id实际上是后生成的,并不是你指定的Repeater2了。 --------------------编程问答-------------------- 嵌套之后,页面里边就不止一个Repeater2了吧 ?不明白 --------------------编程问答-------------------- 顶一下~~~~~~~~~~~~~~~ --------------------编程问答-------------------- 再顶一下..
补充:.NET技术 , ASP.NET