简体   繁体   中英

Initialize a variable in the Webform template and refer it inside a repeater

I am trying to assign an Eval value to a variable and trying to use that inside a repeater. Here's a brief example of what I am trying to do:

 <ItemTemplate>
  <% var test= Eval("year") %>
 <asp:Repeater DataSource='testlist'>
  <ItemTemplate>
  <a class="testclass" href='/testlink/<%= test%>/'>Test this</a>  
  </ItemTemplate>
</asp:Repeater>
</ItemTemplate>

I end up getting this error

 CS0103: The name 'test' does not exist in the current context

I think my syntax is wrong. I tried looking for options for this online but most of them suggested a variable in the code behind. I am working with Sitefinity Webform templates, so would like to avoid code behind. Is there any way to do something on the aspx page itself instead of a code behind? One thing I forgot to mention is that the testlist does not have year property. The year property exists outside the repeater. And hence I want to assign it to a variable and use.

Use like below

 <ItemTemplate>
 <asp:Repeater DataSource='testlist'>
  <a href='/testlink/<%#DataBinder.Eval(Container.DataItem, "test") %>'>Test this</a>  
</asp:Repeater>
</ItemTemplate>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM