I always wanted to know the difference in terms performance between the two methods but I’ve never put them into “battle”.
So, I’ve created an asp.net solution, I added two pages with two GridViews and a SQL Server 2008 Compact Database with over 5000 entries and I’ve put them to the test:
Here are the results!
DataBound event method:
- first load: 2,57s;
- second page on GridView: 1,96s;
- third page on GridView: 2,89s;
- first page again on GridView: 2,76s;
Inline code method:
- first load: 2,76s;
- second page on GridView: 3,52s;
- second page on GridView: 2,31s;
- first page again on GridView: 2,92s;
Results may vary depending on each computer configuration.
The difference in performance between the two examples is very little, almost unnoticed. But the time spent in development is way different.
When using the method with inline code, development takes up to three times less than the one with DataBound event. Same thing with lines of code written.
Download the Visual Studio test example solution from below.