auwall12688 auwall12688 - 1 year ago 112
C# Question

Using Eval("Name") in Function

I'm using .NET webforms. I have a grid view that can use Eval("Name") in the markup and it works fine. However, I need to do some computations on it so in the code behind I made a method called FormatName(String name). I can use that in the markup and it works when I pass it a string but not when I when I try to use Eval("Name".

<%# Eval("Name") %>

< %# FormatName("jim") %>

I'm looking for something like this:

<%# FormatName(Eval("Name"))>%

That doesnt work but I figure there is something close.

Answer Source

<%# FormatName(Eval("Name").ToString())>% should work. Eval returns an object, not a string.

Another option is the EvalText function, which evaluates the value as a string.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download