展开全部
我也遇过两个repeater 嵌套的问题,希望下面代码对你有用
<asp:Repeater ID="rpMenuParent" runat="server" DataSourceID="odsMenuParent" OnItemDataBound="rpMenuParent_ItemDataBound">
<ItemTemplate>
<%-----主功能项table开始-----%>
<table class="menuParentTable" cellpadding="0" cellspacing="0">
<tr style="height: 22px;">
<td style="padding-left: 30px;">
<a class="menuParentLink" onclick='expand(<%#Eval("NodeId")%>)' href="javascript:void(0);" title='<%#Eval("DisplayName")%>'>
<%#Eval("DisplayName")%></a><asp:Label ID="lblNodeId" runat="server" Text='<%#Eval("NodeId")%>' Width="0" Height="0" Visible="false"></asp:Label>
</td>
</tr>
<tr style="height: 4px">
<td>
</td>
</tr>
</table>
<%-----主功能项table结束-----%>
<%-----子功能项table开始-----%>
<table class="menuChildTable" style="display: none;" id='child<%#Eval("NodeId")%>' cellspacing="0" cellpadding="0">
<%-----子功能项内嵌Repeater开始-----%>
<asp:Repeater ID="rpMenuChild" runat="server" DataSourceID="odsMenuChild">
<ItemTemplate>
<tr style="height: 20px; text-align: left;">
<td align="center" style="width: 30px">
<img style="width: 9px; height: 9px;" src="../../images/gamesale/menu_icon.gif" alt="" />
</td>
<td>
<a class="menuChildLink" href='javascript:navToPage("<%#Eval("NodeURL")%>");' target="_self" title='<%#Eval("DisplayName")%>'>
<%#Eval("DisplayName")%></a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<%-----子功能项内嵌Repeater结束-----%>
<%-----数据源控件开始-----%>
<asp:ObjectDataSource ID="odsMenuChild" runat="server" SelectMethod="GetSysFuncByRoleIdAndParentNodeId" TypeName="BSTMyGame.BLL.SysFun">
<SelectParameters>
<asp:Parameter DefaultValue="-1" Name="roleId" Type="Int32" />
<asp:Parameter DefaultValue="-1" Name="parentNodeId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-----数据源控件结束-----%>
</table>
<%-----子功能项table结束-----%>
</ItemTemplate>
</asp:Repeater>
<%-----数据源控件开始-----%>
<asp:ObjectDataSource ID="odsMenuParent" runat="server" SelectMethod="GetSysFuncByRoleIdAndParentNodeId" TypeName="BSTMyGame.BLL.SysFun">
<SelectParameters>
<asp:Parameter DefaultValue="-1" Name="roleId" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="parentNodeId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-----数据源控件结束-----%>
protected void rpMenuParent_ItemDataBound(object sender, RepeaterItemEventArgs e) //给子功能项Repeater的数据源控件赋值,查询子功能项
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ObjectDataSource odsMenuChild = e.Item.FindControl("odsMenuChild") as ObjectDataSource;
if (odsMenuChild != null)
{
odsMenuChild.SelectParameters[0].DefaultValue = RoleId.ToString();
Label lblNodeId = (e.Item.FindControl("lblNodeId")) as Label;
if (lblNodeId != null)
{
odsMenuChild.SelectParameters[1].DefaultValue = lblNodeId.Text;
odsMenuChild.Select();
//DataBinder.Eval(t
// string nodeId = DataBinder.GetDataItem("NodeId").ToString();
}
}
}
}
<asp:Repeater ID="rpMenuParent" runat="server" DataSourceID="odsMenuParent" OnItemDataBound="rpMenuParent_ItemDataBound">
<ItemTemplate>
<%-----主功能项table开始-----%>
<table class="menuParentTable" cellpadding="0" cellspacing="0">
<tr style="height: 22px;">
<td style="padding-left: 30px;">
<a class="menuParentLink" onclick='expand(<%#Eval("NodeId")%>)' href="javascript:void(0);" title='<%#Eval("DisplayName")%>'>
<%#Eval("DisplayName")%></a><asp:Label ID="lblNodeId" runat="server" Text='<%#Eval("NodeId")%>' Width="0" Height="0" Visible="false"></asp:Label>
</td>
</tr>
<tr style="height: 4px">
<td>
</td>
</tr>
</table>
<%-----主功能项table结束-----%>
<%-----子功能项table开始-----%>
<table class="menuChildTable" style="display: none;" id='child<%#Eval("NodeId")%>' cellspacing="0" cellpadding="0">
<%-----子功能项内嵌Repeater开始-----%>
<asp:Repeater ID="rpMenuChild" runat="server" DataSourceID="odsMenuChild">
<ItemTemplate>
<tr style="height: 20px; text-align: left;">
<td align="center" style="width: 30px">
<img style="width: 9px; height: 9px;" src="../../images/gamesale/menu_icon.gif" alt="" />
</td>
<td>
<a class="menuChildLink" href='javascript:navToPage("<%#Eval("NodeURL")%>");' target="_self" title='<%#Eval("DisplayName")%>'>
<%#Eval("DisplayName")%></a>
</td>
</tr>
</ItemTemplate>
</asp:Repeater>
<%-----子功能项内嵌Repeater结束-----%>
<%-----数据源控件开始-----%>
<asp:ObjectDataSource ID="odsMenuChild" runat="server" SelectMethod="GetSysFuncByRoleIdAndParentNodeId" TypeName="BSTMyGame.BLL.SysFun">
<SelectParameters>
<asp:Parameter DefaultValue="-1" Name="roleId" Type="Int32" />
<asp:Parameter DefaultValue="-1" Name="parentNodeId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-----数据源控件结束-----%>
</table>
<%-----子功能项table结束-----%>
</ItemTemplate>
</asp:Repeater>
<%-----数据源控件开始-----%>
<asp:ObjectDataSource ID="odsMenuParent" runat="server" SelectMethod="GetSysFuncByRoleIdAndParentNodeId" TypeName="BSTMyGame.BLL.SysFun">
<SelectParameters>
<asp:Parameter DefaultValue="-1" Name="roleId" Type="Int32" />
<asp:Parameter DefaultValue="0" Name="parentNodeId" Type="Int32" />
</SelectParameters>
</asp:ObjectDataSource>
<%-----数据源控件结束-----%>
protected void rpMenuParent_ItemDataBound(object sender, RepeaterItemEventArgs e) //给子功能项Repeater的数据源控件赋值,查询子功能项
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
{
ObjectDataSource odsMenuChild = e.Item.FindControl("odsMenuChild") as ObjectDataSource;
if (odsMenuChild != null)
{
odsMenuChild.SelectParameters[0].DefaultValue = RoleId.ToString();
Label lblNodeId = (e.Item.FindControl("lblNodeId")) as Label;
if (lblNodeId != null)
{
odsMenuChild.SelectParameters[1].DefaultValue = lblNodeId.Text;
odsMenuChild.Select();
//DataBinder.Eval(t
// string nodeId = DataBinder.GetDataItem("NodeId").ToString();
}
}
}
}
展开全部
例如repeater三层嵌套吧:
repeater2是在repeater1的OnItemDataBound事件获得,获得repeater3当然是在repeater2的OnItemDataBound事件里获得了。能明白么?
repeater2是在repeater1的OnItemDataBound事件获得,获得repeater3当然是在repeater2的OnItemDataBound事件里获得了。能明白么?
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
楼下的应该能解决你的问题
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询