Performance of conditional logic with gridview RowDataBound vs ItemTemplate/Regular databind
<p>I have a gridview that contains around 16 ItemTemplate columns. The values in each column are decimal properties. In each column, I'm doing some conditional logic to display N/A or actual value etc, etc. Something like,</p>

<pre><code>&lt;asp:TemplateField HeaderText="Test" ItemStyle-CssClass="test"&gt;                   
    &lt;ItemTemplate&gt;
            &lt;%# Eval("TestExpense", "{0:n}").ToString() == "-1.00" ? "N/A" : "$" + Eval("TestExpense", "{0:n}")%&gt; 
    &lt;/ItemTemplate&gt;
&lt;/asp:TemplateField&gt;
</code></pre>

<p>The grid returns many rows, say 30,000 in most cases. There is paging for the grid so only 10 rows are visible at a time. (Yes, I do bring all rows from the db back, no paging in SQL. The search is complicated and takes time)</p>

<p>The question is, should I do this logic in the RowDataBound Event where I can say do this logic only when the row is visible. This makes sure that only 10 visible rows (for the active page) are processed with this logic at a time. If I do a regular databind, is the datagrid smart enough to do the ItemTemplate logic only for 10 rows or does it do for all 30,000 rows. That will be unnecessary.</p>

<p>To add to this question, I have some Template columns that are derived from other properties. If I do a regular databind, does the grid calculate through all the columns for each row or only does it for the visible rows.</p>

<p>I believe if I use the RowDataBound event, I can control all this. But the other option is more convenient. If the gridview automatically does this, then I don't have to worry about it. Any thoughts?</p>
