• Repeater嵌套绑定Repeater


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

    cs代码:

    privatevoid RpTypeBind()         {//GetQuestionTypeAndCount() 返回一个datatable            this.rptypelist.DataSource = LiftQuestionCtr.GetQuestionTypeAndCount();                               this.rptypelist.DataBind();         }                protectedvoid 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嵌套,datalist嵌套。

  • 相关阅读:
    【刷题】BZOJ 3626 [LNOI2014]LCA
    【刷题】UOJ #207 共价大爷游长沙
    【刷题】COGS 2701 动态树
    【刷题】BZOJ 4530 [Bjoi2014]大融合
    【刷题】BZOJ 2959 长跑
    【刷题】BZOJ 1969 [Ahoi2005]LANE 航线规划
    【刷题】BZOJ 4998 星球联盟
    【刷题】BZOJ 1977 [BeiJing2010组队]次小生成树 Tree
    【刷题】BZOJ 4817 [Sdoi2017]树点涂色
    获取元素 在网页中的 坐标
  • 原文地址:https://www.cnblogs.com/altman29/p/2523817.html
Copyright © 2020-2023  润新知