2016-09-26 9 views
0

I have a code which I want to dynamically generate the text by using a foreach class type property value<a > tag dynamically text generation issue

but when ever I run it, generates a compile time error

Refer the code segment below.

<ul class="nav nav-pills nav-stacked"> 
         <% 
          List<CodeCamper.EntityLayer.Transaction.SessionVO> y = new List<CodeCamper.EntityLayer.Transaction.SessionVO>(); 

          CodeCamper.EntityLayer.Transaction.SessionVO x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
          x.SessionTimeSlot = "Day 01"; 
          y.Add(x); 

          x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
          x.SessionTimeSlot = "Day 02"; 
          y.Add(x); 

          x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
          x.SessionTimeSlot = "Day 03"; 
          y.Add(x); 


          foreach (CodeCamper.EntityLayer.Transaction.SessionVO s in y) 
          { 
           %> 
           <li class="active"><a href="#" runat="server" onserverclick="sample_Click"><%= s.SessionTimeSlot %></a></li> 
           <% 
          }        
          %> 

         <%-- <li class="active"><a href="#">Home</a></li> 
         <li class="active"><a href="#">sfsfs</a></li>--%> 
        </ul> 

The compile time error is Compiler Error Message: CS0103: The name 'item' does not exist in the current context

Hope for a correction of this code

enter image description here

+0

はあなたがエラーコードを表示することができますことができます....スクリーンショットコンパイルエラーの –

+0

@ユートシュラン私はオリジナルの質問をスクリーンショットで変更します – Sanjeewa

答えて

1

私は<%= s.SessionTimeSlot %>があなたの問題だと信じています。 この目的でRepeaterを使用する必要があります。

<asp:Repeater ID="SessionVORepeater" runat="server"> 
    <ItemTemplate> 
     <li class="active"><a href="#" runat="server" onserverclick="sample_Click"><%# DataBinder.Eval(Container.DataItem, "SessionTimeSlot") %></a></li> 
    </ItemTemplate> 
</asp:Repeater> 

と背後にあるコードで

(をPage_Load例):

このような何かを試してみてください

     List<CodeCamper.EntityLayer.Transaction.SessionVO> y = new List<CodeCamper.EntityLayer.Transaction.SessionVO>(); 

         CodeCamper.EntityLayer.Transaction.SessionVO x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
         x.SessionTimeSlot = "Day 01"; 
         y.Add(x); 

         x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
         x.SessionTimeSlot = "Day 02"; 
         y.Add(x); 

         x = new CodeCamper.EntityLayer.Transaction.SessionVO(); 
         x.SessionTimeSlot = "Day 03"; 
         y.Add(x); 

         SessionVORepeater.DataSource = y; 
         SessionVORepeater.DataBind(); 

希望を、これは

+0

'<%#DataBinder.Eval(Container.SessionTimeSlot、" SessionTimeSlot ")%>'を ' ### DataBinder.Eval(Container.DataItem、 "SessionTimeSlot")%> '、申し訳ありません:) – DerpyNerd

+0

asp:リピーターは出力を生成せず(空白領域)、<%:s.SessionTimeSlot%>はコンパイル時エラーを生成します – Sanjeewa

+0

リピータにバインドされているときに 'y'が空ではないのは確かですか? 出力ウィンドウに解析エラーなどが含まれていますか? – DerpyNerd

関連する問題