Click here to Skip to main content
13,260,161 members (53,245 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked
Posted 27 Nov 2012

Using Explicit Cast instead of Databinder.Eval to Increase Performance

, 27 Nov 2012
Rate this:
Please Sign up or sign in to vote.
Increase ASP.NET Application performance with explicit casting


The DataBinder.Eval method is used to bind data to a control's template. DataBinder.Eval casts Container.DataItem to its specific type, like this:

<%# DataBinder.Eval(Container.DataItem,"UserName") %>

DataBinder.Eval uses .NET reflection to cast Container.DataItem to its specific type which results in a performance loss. So it is better to use explicit casting.

Option 1 - Cast the Container.DataItem as a DataRowView if the data source is a DataSet.

<div><%# ((DataRowView)Container.DataItem)["UserName"] %>

Option 2 for DataReader

<%# ((DbDataRecord)Container.DataItem)["UserName"] %>

Cast the Container.DataItem as a String if the data source is an Array or an ArrayList.

<%# ((String)Container.DataItem)["UserName"] %>


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Fenil Desai
Software Developer (Senior)
India India
IT Analyst/ Senior Software Engineer with 4+ years of experience in MS.NET Technologies

You may also be interested in...


Comments and Discussions

QuestionMetrics? Pin
Marcus Kramer27-Nov-12 5:00
memberMarcus Kramer27-Nov-12 5:00 
AnswerRe: Metrics? Pin
Fenil Desai27-Nov-12 20:35
memberFenil Desai27-Nov-12 20:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171114.1 | Last Updated 27 Nov 2012
Article Copyright 2012 by Fenil Desai
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid