Using in "Eval" in databound controls

Using in "Eval" in databound controls

Post by Newis » Fri, 29 Sep 2006 16:38:49


Hi

Is it really not recommended to us Eval in databound controls as
follows:

<td><asp:TextBox id="BookTitle" Runat="Server"
Text='<%# Eval("BookTitle") %>'
Font-Size="8pt" Width="80px"/></td>

If so what is the alternative.

Thanks

Newish
 
 
 

Using in "Eval" in databound controls

Post by Eliyahu Go » Fri, 29 Sep 2006 18:19:10

It is fine to use Eval. You do pay for this some performance penalty, but it
might be insignificant. You gain independence of the datasource. Whether it
is a table, or an array or whatever else, Eval takes care of it.

The alternative is to have expressions like
<%# ((DataRowView)Container.DataItem)["BookTitle"] %>

This is good for a datatable, but won't work if you change the datasource to
an array.

--
Eliyahu Goldin,
Software Developer & Consultant
Microsoft MVP [ASP.NET]