Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET Is it possible to call methods within Server Tag using Eval()?

Tags:

c#

asp.net

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?

like image 867
Theomax Avatar asked Oct 03 '11 10:10

Theomax


People also ask

How does Eval work in asp net?

Eval function is used to bind data to control inside a DataBound control, but it cannot update the values back to the database. Bind function can be used to bind data to control inside a DataBound control and also it can update the values back to the database.

What is Eval in asp net GridView?

Eval) function is used to bind data in controls inside GridView, DataList, Repeater, DetailsView, etc. and using string. Format multiple values can be set to a single control. HTML Markup.

What is Eval in VB net?

The Eval function evaluates the string expression and returns its value. For example, Eval("1 + 1") returns 2. If you pass to the Eval function a string that contains the name of a function, the Eval function returns the return value of the function.


1 Answers

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")) %>
like image 128
Adrian Iftode Avatar answered Nov 10 '22 23:11

Adrian Iftode