ASP.NET Is it possible to call methods within Serv

2020-07-11 08:05发布

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?

标签: c# asp.net
1条回答
狗以群分
2楼-- · 2020-07-11 08:33

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")) %>
查看更多
登录 后发表回答