开发者

Performance of conditional logic with gridview RowDataBound vs ItemTemplate/Regular databind

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,

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

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 tim开发者_JAVA技巧e. (Yes, I do bring all rows from the db back, no paging in SQL. The search is complicated and takes time)

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.

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.

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?


RowDataBound and the inline code in the template field is only executed for the active page (10 rows in your case)

If your not doing anything to complex I see no problem keeping it as inline code in template field.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜