• Repeat 嵌套绑定


    参考 http://www.cnblogs.com/apiaceae/articles/1489265.html

    直接贴代码

    aspx文件

    代码
    <asp:Repeater ID="Rep_AppClass" runat="server" 
                        onitemdatabound
    ="Rep_AppClass_ItemDataBound" >
                    
    <ItemTemplate>
                     
    <div><span class="ftst">
                     
                 
           
                     
    <%#(((Application.ApplyClass)Container.DataItem)).ApplyClassName.ToString().Length > 4 ? (((Application.ApplyClass)Container.DataItem)).ApplyClassName.ToString().Substring(04) : (((Application.ApplyClass)Container.DataItem)).ApplyClassName.ToString()%>
                    
    </span>
                    
                      
    <asp:Repeater ID="Rep_AppInfo" runat="server">
                      
    <ItemTemplate>
                      
    <%# Container.ItemIndex >2" <span style=\"display: none;\">" : ""%>
                              
                      
    <href="Apply/IntoApply.aspx?applyid=<%#(((Application.Applications)Container.DataItem)).ApplyId%>" title="<%#(((Application.Applications)Container.DataItem)).ApplyName%>" target="_blank">
                      
    <%#(((Application.Applications)Container.DataItem)).ApplyName.ToString().Length > 4 ? (((Application.Applications)Container.DataItem)).ApplyName.ToString().Substring(04) : (((Application.Applications)Container.DataItem)).ApplyName.ToString()%>
                      
    </a>
                        
    <%# Container.ItemIndex >2 ? "</span>" :""%>
                      
    </ItemTemplate>
                      
    </asp:Repeater>
                    
    </div>
                    
    </ItemTemplate>
                    
    <FooterTemplate>
                    
    <div><span class="ftst">视频会议:</span>正在开发...</div><div><span class="ftst">电子杂志:</span>正在开发...</div>
                    
    </FooterTemplate>
                 
    </asp:Repeater>

     后台的cs 文件 

    代码

        
    #region 获取应用插件分类
        
    public void GetApplicationList()
        {
         
            IList
    <ApplyClass> typelist = apply.GetDescApplyClass();
            Rep_AppClass.DataSource 
    = typelist;
            Rep_AppClass.DataBind();
        }
        
    #endregion


        
    #region 应用分类信息列表
        
    /// <summary>
        
    ///  应用分类信息列表
        
    /// </summary>
        
    /// <param name="sender"></param>
        
    /// <param name="e"></param>
        protected void Rep_AppClass_ItemDataBound(object sender, System.Web.UI.WebControls.RepeaterItemEventArgs e)
        {
           

            
    if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
            
                
    string NowApplyClassId = ((ApplyClass)e.Item.DataItem).ApplyClassId.ToString();
                Repeater Rep_AppInfo 
    = (Repeater)e.Item.FindControl("Rep_AppInfo");

                
    if (Rep_AppInfo != null)
                {
                    Predicate
    <Applications> FindValue = delegate(Applications obj) { return obj.ApplyClassId == NowApplyClassId; };
                    List
    <Applications> info = applylist.FindAll((c) => { return c.ApplyClassId == NowApplyClassId; });
                    Rep_AppInfo.DataSource 
    = info;
                    Rep_AppInfo.DataBind();
                }
            }
        }
        
    #endregion

     ListItemType.AlternatingItem 要引用 System.Web.UI.WebControls

     如果你绑定的数据并非一个实体类,可以通过如下方式获取,

        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
            {
           Repeater Repeater3 = (Repeater)e.Item.FindControl("Repeater3");
           
    string DatumArticleID = ((DataRowView)(e.Item.DataItem))["DatumArticleID"].ToString();
            if (Rep_AppInfo != null)
                {
                    Predicate
    <Applications> FindValue = delegate(Applications obj) { return obj.ApplyClassId == NowApplyClassId; };
                    List
    <Applications> info = applylist.FindAll((c) => { return c.ApplyClassId == NowApplyClassId; });
                    Rep_AppInfo.DataSource 
    = info;
                    Rep_AppInfo.DataBind();
                }
            }

    //在HeaderTemplate中寻找Label1,默认为第0个

    string s=((Label)Repeater1.Controls[0].FindControl("Label1")).Text;

    //在FooterTemplate中寻找Label2,默认为最后一个

    string s=((Label)Repeater1.Controls[Repeater1.Controls.Count - 1].FindControl("Label2")).Text;


     

  • 相关阅读:
    Java中Collections的min和max方法
    Java中Collections的frequency方法
    Java中Collections的binarySearch方法
    uniapp 样式记录
    uniapp记录
    uniapp 弹窗输入
    uniapp 扫描
    uniapp for显示数据改变时,绑定的list值同时改变
    dev随笔记录
    easyui 使用技巧
  • 原文地址:https://www.cnblogs.com/dooom/p/1644377.html
Copyright © 2020-2023  润新知