简体   繁体   中英

Using Directives

If I have a repeater going through a list of data to retieve the values I use

<%# Eval("current_item") %>

And with a bit of luck it outputs the information for "current_item"

However if I want to check if "current_item" equals 1 for instance, this will tell me whether to print the next lot of information. So how do I use that information to determine the output, effectivily I want to put that information into an variable.

<%# myInt = int.Parse(Eval("current_item")) %>

The above code is what I want to do really.

Then I will do something like this:

<% if (myInt == 1) { %>
<p>Information to display if myInt = 1</p>
<% } else { %>
<p>Other Information</p>
<% } %>

Any Ideas?

I have used something similar to the following in a GridView:

<p>
    <asp:Label Visible='<%# ((int)Eval("current_item") == 1) %>' Text="This is the first item" runat="server" />
    <asp:Label Visible='<%# ((int)Eval("current_item") != 1) %>' Text="This is not the first item" runat="server" />
</p>

Give that a shot and see if it works for a Repeater too.

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