首页 > 其他 > 详细

Repeater嵌套Repeater的结构

时间:2020-08-03 17:07:48      阅读:67      评论:0      收藏:0      [点我收藏+]

Repeater嵌套Repeater的结构:一般写过的都能看懂吧

 cs代码: 

 

技术分享图片
private void RpTypeBind()
        {//GetQuestionTypeAndCount() 返回一个datatable
            this.rptypelist.DataSource = LiftQuestionCtr.GetQuestionTypeAndCount();                   
            this.rptypelist.DataBind();
        }
               protected void rptypelist_ItemDataBound(object sender, RepeaterItemEventArgs e)
        {

//判断里层repeater处于外层repeater的哪个位置( AlternatingItemTemplate,FooterTemplate,

//HeaderTemplate,,ItemTemplate,SeparatorTemplate)
            if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
                Repeater rep = e.Item.FindControl("rpquestionlist") as Repeater;//找到里层的repeater对象
                DataRowView rowv = (DataRowView)e.Item.DataItem;//找到分类Repeater关联的数据项 
                int typeid = Convert.ToInt32(rowv["qtid"]); //获取填充子类的id 
                rep.DataSource = LiftQuestionCtr.GetSomeQuestionsByTypeid(typeid, 2);
                rep.DataBind();
            }
        }

 

aspx:

技术分享图片
<table border="0" cellpadding="0" cellspacing="0" style="margin-bottom: 5px" width="100%">
    <asp:Repeater runat="server" ID="rptypelist" OnItemDataBound="rptypelist_ItemDataBound">
        <ItemTemplate>
            <tr>
                <td class="fb">
                    &nbsp;&nbsp;<a href="Lists.aspx?Qtid=<%#Eval("qtid") %>"><%#Eval("qtypename") %></a> <span id="askCount_15"
                        class="date2">[<%#Eval("typecount")%>]</span>
                </td>
            </tr>
            <tr>
                <td>
                    <div id="askTop2_15" class="ask_list">
                        <asp:Repeater runat="server" ID="rpquestionlist">
                            <ItemTemplate>
                                <a href="Question.aspx?qid=<%#Eval("liftquestionid")%>">
                                    <%#Eval("questiontitle")%></a><br />
                            </ItemTemplate>
                        </asp:Repeater>
                    </div>
                </td>
            </tr>
        </ItemTemplate>
    </asp:Repeater>
</table>

 

Repeater嵌套Repeater的结构

原文:https://www.cnblogs.com/jj123/p/13427192.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!