zoukankan      html  css  js  c++  java
  • 转:Repeater嵌套绑定Repeater以及内层调用外层数据

    <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 />
    
                                         父级数据:<%# DataBinder.Eval(((RepeaterItem)Container.Parent.Parent).DataItem, "qtid")%>
                                         父级序号:<%# ((RepeaterItem)Container.Parent.Parent).ItemIndex %>
    
                                </ItemTemplate>
                            </asp:Repeater>
                        </div>
                    </td>
                </tr>
            </ItemTemplate>
        </asp:Repeater>
    </table>
    private void Repeater1Bind()
            {//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();
                }
            }
  • 相关阅读:
    无题..
    让Windows 2003 Server支持ASP程序
    下雪
    比较经典的.NET基础
    XML几种操作
    某年某月有几天
    .NET操作Word(傻瓜型)
    XML 简单操作
    一首歌
    ASP.NET:掌握Web窗体的生命周期与状态管理(摘自网络)
  • 原文地址:https://www.cnblogs.com/Unrmk-LingXing/p/4074291.html
Copyright © 2011-2022 走看看