Search code examples
asp.netperformancedatabound-controls

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)?


Solution

  • 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).