Click here to Skip to main content
11,920,772 members (58,900 online)
Click here to Skip to main content
Add your own
alternative version


8 bookmarked

Using Explicit Cast instead of Databinder.Eval to Increase Performance

, 27 Nov 2012 CPOL
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.

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