Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Eval and ItemDataBound or RowDataBound event to display data, which one is better?

Which method is better (performance-wise) if I have DataBoundControl such as GridView, Repeater, and/or DataList and I use the following method to display data:

Eval("ColumnName")

or handling the ItemDataBound or RowDataBound event like:

void Repeater1_ItemDataBound(object sender, RepeaterItemEventArgs e) 
{
    // my code to display data here
}

I prefer the second one for code readability reason, but for performance reason, are they the same (or are they even the same thing)?

like image 454
Arief Avatar asked Nov 04 '10 13:11

Arief


2 Answers

I also prefer the second version. It's easier for debugging and separation of html & code in my opinion.

According to this older doc, Improving .NET Application Performance and Scalability, it's more efficient (mentioned on page 297).

like image 86
Lareau Avatar answered Nov 08 '22 00:11

Lareau


Eval might be faster(depends on the situatiuon, because it is also latebound and uses reflection), but via DataBound-Event it is more readable and more future-proof.

like image 33
Tim Schmelter Avatar answered Nov 07 '22 22:11

Tim Schmelter