Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the standard ASP.net data binding syntax?

Microsoft's introduction to data-binding using the asp:Repeater control gives the syntax to fetch a value:

<b><%# DataBinder.Eval(Container.DataItem, "orderid") %></b>

This syntax is repeated on other introductions to the ASP.net Repeater control:

<a href="<%# DataBinder.Eval(Container.DataItem, "URL") %>">...</a>

But i remember this syntax being "bad" and "wrong". From the MSDN documentation of DataBinder.Eval i see:

enter image description hereNote

Because this method performs late-bound evaluation, using reflection at run time, it can cause performance to noticeably slow compared to standard ASP.NET data-binding syntax.

(emphases added)

So that explains why i had a memory of "Eval is bad". But what is the "standard ASP.NET data-binding syntax"?

Bonus Reading

  • Data-Binding Expression Syntax
like image 533
Ian Boyd Avatar asked Oct 07 '22 20:10

Ian Boyd


1 Answers

I think you can just do a cast to avoid the "late binding" penalty:

<%# (((System.Data.DataRowView)Container.DataItem)["URL"]) %>

Now let's say you increase performance by x%. Is it worth it to your application? The trade-off (in my opinion) is less readability.

like image 142
Kris Krause Avatar answered Oct 12 '22 11:10

Kris Krause