在Repeater中嵌套使用Repeater

sukewan123456 2007-04-16 10:32:37
谁能告诉我。在Repeater中嵌套使用Repeater怎么写,给份完整的代码。谢谢
...全文
175 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
Zeilg1981 2007-04-16
  • 打赏
  • 举报
回复
ls正解~
Aricc 2007-04-16
  • 打赏
  • 举报
回复
在外层Reapter的ItemDataBound事件中设置内层Reapter的DataSource并调用DataBind方法
luyesql 2007-04-16
  • 打赏
  • 举报
回复
Repeater 好像不好嵌套吧,因为它没有datakeyfield这个属性.
一般是用datagrid或datalist.
看一下别人有没有好的方法
石翮 2007-04-16
  • 打赏
  • 举报
回复
在HTML页面中你可以看看如何设置父子表的关联。
下面是CS代码:
public class index : System.Web.UI.Page
{
protected System.Web.UI.WebControls.DataList rep_boardlist;
protected System.Web.UI.HtmlControls.HtmlForm Form1;
protected System.Web.UI.WebControls.Repeater rep_smallboard;
protected System.Web.UI.WebControls.Label l_name;
protected System.Web.UI.WebControls.Panel Panel1;
protected System.Web.UI.WebControls.Label l_lasttime;
protected System.Web.UI.WebControls.Label l_userpoint;
private ForumClassHdl forumclasshdl=new ForumClassHdl();
private User user=new User();
private void Page_Load(object sender, System.EventArgs e)
{
user=(User)Session["userObj"];
if(user!=null)
{
this.Panel1.Visible=true;
this.l_name.Text=user.UserName;
this.l_userpoint.Text=user.UserPoint;
this.l_lasttime.Text=user.User_LastLogin;
}
else
{
this.Panel1.Visible=false;
this.l_userpoint.Text="无积分";
this.l_name.Text="游客";
}
this.rep_boardlist.DataSource=forumclasshdl.selectForumClass(3,null);
this.rep_boardlist.DataBind();
}
石翮 2007-04-16
  • 打赏
  • 举报
回复
可以嵌套使用的!!比如说在论坛上使用,大类版块和小类版块的循环。不过我的做法是大类使用的是“DATALIST”:protected System.Web.UI.WebControls.DataList rep_boardlist;
小类使用的是“Repeater ”:protected System.Web.UI.WebControls.Repeater rep_smallboard;

具体页面中代码如下:

<asp:DataList ID="rep_boardlist" Runat="server" Width="100%" >
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<DIV align=center>
<DIV class="spaceborder spacebottom" style="CLEAR: both; MARGIN-TOP: 5px; WIDTH: 98%">
<TABLE cellSpacing="0" cellPadding="4" width="100%" align="center">
<TR>
<TD class="header" style="PADDING-LEFT: 20px" colSpan="7">
<DIV class="subtable" style="PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px">
<DIV class="right"><FONT color="#154ba0">分类版主: <A href="#">
<%#DataBinder.Eval(Container.DataItem,"Forum_BigClass_manager")%>
</A></FONT><A onClick="toggle_collapse('category_1');" href="###">
<IMG id="category_1_img" alt="" src="images/collapsed_no.gif" border="0"></A> 
</DIV>
<A href="#">
<%#DataBinder.Eval(Container.DataItem,"Forum_BigClass_name")%>
</A>
</DIV>
</TD>
</TR>
<asp:DataList Width=100% ID="rep_smallboard" Runat="server" DataSource='<%# ((System.Data.DataRowView)(Container.DataItem)).CreateChildView("relations")%>' DataKeyField="Forum_SmallClass_id">
<HeaderTemplate>
<TBODY id="category_1">
<TR class="category" align="center">
<TD width="5%"> </TD>
<TD align="left" width="56%">论坛</TD>
<TD width="5%">主题</TD>
<TD width="5%">帖数</TD>
<TD width="13%">最后发表</TD>
<TD width="16%">版主</TD>
</TR>
</HeaderTemplate>
<ItemTemplate>
<TR class="row" onMouseOver="this.className='row1'" onmouseout="this.className='row'">
<TD align="center" width="5%"><IMG alt="" src="images/forum.gif"></TD>
<TD class="subject" align="left" width="56%"><A href='board.aspx?smallid=<%#DataBinder.Eval(Container.DataItem,"Forum_SmallClass_Id")%>'><SPAN class="bold">『<%#DataBinder.Eval(Container.DataItem,"Forum_SmallClass_name")%>』</SPAN></A>
<BR>
<SPAN class="smalltxt"></SPAN>
</TD>
<TD align="center"><%#DataBinder.Eval(Container.DataItem,"Forum_SmallClass_topicnum")%></TD>
<TD align="center"><%#DataBinder.Eval(Container.DataItem,"Forum_SmallClass_postnum")%></TD>
<TD title="标题: 请看紫气东来董事长年终如何表扬员工的" noWrap align="center"><SPAN class="smalltxt"><A href="http://bbs.syd.com.cn/redirect.php?tid=27329&goto=lastpost#lastpost"><%#DataBinder.Eval(Container.DataItem,"Forum_SmallClass_lastpost")%></A></SPAN><BR>
by <A href="http://bbs.syd.com.cn/viewpro.php?username=%D3%D0%BB%B0%BA%C3%BA%C3%CB%B5">
有话好好说</A></TD>
<TD style="WORD-BREAK: keep-all" align="center"> </TD>
</TR>
</ItemTemplate>
<FooterTemplate>
</TABLE>
</DIV>
<BR>
</DIV> </FooterTemplate> </asp:DataList></ItemTemplate> </asp:DataList>

62,025

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧