2013-12-23 23 views
0

我想在asp.net後增加新的,和我的HTML代碼如何動態地添加HTML裏控制中繼

<asp:repeater ID="Repeater1" runat="server" onitemdatabound="Repeater1_ItemDataBound"> 
    <ItemTemplate> 
     <ul class="slider carousel" id="sliderName"> 
      <li class="slide"> 
      <div class="one-third column alpha portfolio-item"> 
       <div class="content"> 
        <div class="border"> 
         <asp:Image ID="imgHotels" runat="server" Width="300px" Height="130px" class="scale-with-grid" /> 
         <a href="" class="prettyPhoto zoom"></a> 
         <a class="link" href=""></a> 
        </div> 
        <center><h5 class="noline"><a href="#"> 

        <asp:Label Visible ="false" ID="lblhotelid" runat="server" Text='<%#Eval("SrNo") %>'></asp:Label>  
        <asp:Label ID="lblhotelname" Visible="true" runat="server" Text='<%#Eval("hotelname") %>'></asp:Label> 

        </a></h5></center> <div class="shadow"> 
       </div> 
      </div> 
      </div> 
     </li> 
     </ul> 
    </ItemTemplate> 

,我怎麼能在這個代碼添加HTML控件li

 if (repeat % 3 == 0) 
     { 
      HtmlGenericControl li = new HtmlGenericControl();//create the html control li 
} 

感謝,求助

回答

1

在代碼隱藏中生成html控件是一種不好的做法。

試試這個:

<li runat="server" Id="liControl" Visible='<%# Container.ItemIndex % 3 == 0 ? "true" : "false" %>' >...</li> 

<% if(Container.ItemIndex % 3 == 0) { %> 
    <li>...</li> 
<% } %> 
0

將文字要插入的repeater項目模板extral李

找到行數據綁定相同,數據分配給text屬性 一些像下面的東西。

if (repeat % 3 == 0) 
    { 
     Literal ltrlLiContent=(Literal)e.Item.FindControl("lstrLiContent"); 

     string strDataForli=""; //fill your content with li tags into this variable 

     ltrlLiContent.Text=strDataForli; 
    }