asp.net Repeater嵌套绑定详细做法

作者:袖梨 2022-06-25

我做东西的时候,有几个父子关系的表,例如,新闻大标题套小标题,小标题套小小标题,大概几个把,我是用的repeater,一曾一个,下面是一个,我又在repeater2里套了repeater3,repeater3了套了。。。。

<%datetime   last   =   new   datetime();
  foreach   (nonocast.domain.entry   e   in   nonocast.domain.entrymanager.instance.reversefindall())   {
  if   (!nonocast.domain.kalendar.issameday(last,   e.date))   {   %>
<%   if   (nonocast.domain.kalendar.istoday(e.date))   {   %>
today
<%   }   else   if   (nonocast.domain.kalendar.isyesterday(e.date))   {   %>
yesterday
<%   }   else   {   %>

<%=e.date.tostring( "d ",   system.globalization.datetimeformatinfo.invariantinfo)%>


<%   }   %>
<%   }%>


     <%=e.time.toshorttimestring()%>
   <%=e.title%>


<%   last   =   e.date;%>
<%   }%>

repeater嵌套绑定repeater做法
asp教程.net代码


   
       
           

               
           
           
               
           
       
   

                      "><%#eval("qtypename") %>                         class="date2">[<%#eval("typecount")%>]
               

                   

                       
                           
                                ">
                                    <%#eval("questiontitle")%>


                           

                       

                   

               

 
cs代码

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

相关文章

精彩推荐