Search code examples
c#asp.netevalrepeater

How to use Eval() data in a method within a repeater


I've written a method that checks and returns the status code of a URL. Then I used a repeater to grab rows from my db. What I'm trying to figure out is how to use the data returned in the repeater in a method called within the repeater. Here's the code for the ItemTemplate.

<ItemTemplate>
    <tr class="alt">
        <td><%# Eval("Bounce_from") %></td>
        <td><%# Eval("Bounce_to") %></td>
        <td><%# Eval("is301") %></td>
        <td><% Response.Write(exist(Eval("Bounce_to")));  %></td>
    </tr>
</ItemTemplate>

<% Response.Write(exist(Eval("Bounce_to"))); %> is where I'm struggling. I've searched and can't find the answer. Hopefully someone can point me in the right direction...thanks in advance.


Solution

  • Just as simple as

    <td><%# exist(Eval("Bounce_to")) %></td>
    

    This is assuming exist is available on the markup (it should at least protected page method) and accepts object as an input argument since Eval returns object.

    Basically <%# %> runs whatever code is inside it in data binding context (thus Eval is available) and outputs the final value to the markup.