Hi,
I need to access the value of a bound item several times in a template. Right now my ListView template looks like this:
<asp:ListView ID="ListView1" runat="server" ItemPlaceholderID="plc"><br/>
<ItemTemplate><br/>
<input type="radio" class="myrating<%# DataBinder.Eval(Container.DataItem, "Day")%>" value="3" /><br/>
<input type="radio" class="myrating<%# DataBinder.Eval(Container.DataItem, "Day")%>" value="4" /><br/>
</ItemTemplate><br/>
<LayoutTemplate><br/>
<div id="plc" runat="server"><br/>
</div><br/>
</LayoutTemplate><br/>
<EmptyDataTemplate><br/>
No data</EmptyDataTemplate><br/>
</asp:ListView><br/>
Under certain conditions I may have dozens of radio button so repeatedly calling <%# DataBinder.Eval(Container.DataItem, "Day")%>
seems to be inefficient.
I would like to assign the value of that expression to a variable and then use this variable instead so my template would look something like this
<ItemTemplate><br />
<%String ClassName = "myrating" + <%# DataBinder.Eval(Container.DataItem, "Day")%><br />
<input type="radio" class="<%=ClassName %>" value="3" /><br />
<input type="radio" class="<%="ClassName" value="4" /><br />
</ItemTemplate><br />
This example doesn't compile but I hope you are getting the idea.