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?
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.
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.
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.
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")) %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With