Take the 2-minute tour ×

I'm looking forward to refactor some pieces of application and there are many lines of code that look like this:

<asp:TemplateField HeaderText="Name">
        <%# Eval("Employee.LAST_NAME")%>
<asp:TemplateField HeaderText="First Name">
        <%# Eval("Employee.FIRST_NAME")%>

When refactoring property names (LAST_NAME, FIRST_NAME) Visual Studio doesn't of course find these references to properties in Eval. So now, when I'm refactoring would like to replace it with something type-safe + something that can be spotted during compile time, just in case in the future I need to refactor once again. Is there any way to replace Eval with better mechanism?

share|improve this question
In the next version of Visual Studio, you can do strongly typed data binding, asp.net/vnext/overview/whitepapers/whats-new#_Toc318097385 –  graham mendick Jun 5 '12 at 9:56
@grahammendick: You just made my day! –  Luis Filipe Oct 29 '13 at 16:34
add comment

1 Answer

up vote 4 down vote accepted

Eval is evil (why is a long answer - search SO), use ((Employee)Container.DataItem).LAST_NAME and ((Employee)Container.DataItem).FIRST_NAME instead - its faster, type safe, refactor friendly, etc...

share|improve this answer
even better is to use the asp.net 4.5 strongly type data binding, just like graham mendick referred –  Luis Filipe Oct 29 '13 at 17:12
@LuisFilipe: you're right, but at the time of my answer it was still in beta... –  Nikola Bogdanović Oct 29 '13 at 19:40
Nevertheless i up voted your question :) –  Luis Filipe Oct 29 '13 at 22:15
add comment

Your Answer


