Repeat 嵌套绑定

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

 

直接贴代码

aspx文件

ExpandedBlockStart.gif 代码
< 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( 0 4 ) : (((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( 0 4 ) : (((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 文件 

ExpandedBlockStart.gif 代码

    
#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;


 

转载于:https://www.cnblogs.com/dooom/archive/2010/01/11/1644377.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值