zoukankan      html  css  js  c++  java
  • 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;


     

  • 相关阅读:
    [转]ArcSDE数据被锁定后的解锁方法
    一个ArcGIS网络分析的最短路径例子||A Network Analyst Shortest Route of ArcGIS[转]
    Flex项目调试及日志记录
    组件服务计算机我的电脑右键无属性,组件服务打不开
    ORACLE纯SQL实现多行合并一行[转]
    自定义组件开发 第二节 MXML组件开发
    FLEX中使用BitmapFill的source属性指定SVG类文件
    FLEX动态创建事件
    Sublime Text3常用插件推荐
    RemoveView在android2.1以及之后才支持addView
  • 原文地址:https://www.cnblogs.com/dooom/p/1644377.html
Copyright © 2011-2022 走看看