6

I have an aspx page which contains a repeater. I can output data using Eval() but I want to know if it is possible to call a method that belongs to another class and pass it the value of Eval()?

For example, in the <ItemTemplate> section of the repeater:

<ItemTemplate>
    <tr>
       <td>
          <%# ClassName.Method( Eval("value1") ) %>
       </td>
       <td>
          <%#  Eval("value2") %>
       </td>
    </tr>                  
 </ItemTemplate>

If it is possible to do this, what is the correct way to do it?

1 Answer 1

13

Yes, but you need to provide the full name and to cast the result of the Eval function, which returns System.Object instances.

<%# Namespace.ClassName.Method( (string)Eval("value1") ) %>

Here, method is public static, but you can use instance methods also.

<%# new Namespace.ClassName((string)Eval("value1")).Method2((int)Eval("value2")) %>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.