zoukankan      html  css  js  c++  java
  • asp.net(C#)中Repeater嵌套绑定Repeater

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

        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();
            }
        }


     

    <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">
                          <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>


     

  • 相关阅读:
    adb命令(一)
    appium-DesiredCapability详解与实战
    Appium-appium日志分析
    Appium-关于appium的原生控件的 xpath 定位问题及常用方法
    Appium-xpath详解
    appium界面元素介绍
    Python3.5.1 下使用HTMLParser报错
    Python3 将configparser从ini文件中读取的内容转换成字典格式
    Django forms 关于select和checkbox设置初始选中值
    Django admin注册model究竟要怎么写才优雅
  • 原文地址:https://www.cnblogs.com/smartsmile/p/6234359.html
Copyright © 2011-2022 走看看