>
 Monday, August 22, 2005
« I'm not rich, but this ASP.NET 2.0 sampl... | Main | ASP.NET 2.0 Data Binding Tips - Complex ... »

Sure, the syntax got easier. Instead of the cumbersome:

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

We get to save some strokes and remove the entire confusion around “what the heck is Container.DataItem?“:

<%# Eval("url") %>

But, this isn't all its cracked up to be. Eval() STILL uses reflection to evaluate expressions, therefore for every bound column/row displayed in your ASP.NET pages, you are adding overhead, unnecessarily. Of course, what this really means is, just like with 1.1, you should be using explicit casts to cast Container.DataItem to its actual type:

<%# ((System.Data.DataRowView)Container.DataItem)["url"]) %>

Of course the trick is to know...you guessed it...what the heck is Container.DataItem??? A quick way to find this out for various objects you may choose to employ in binding, is to bind just to Container.DataItem as a test. In the attached example I bound the GridView control to the Web configuration sections:

Configuration webConfig = System.Web.Configuration.WebConfigurationManager.OpenWebConfiguration(Request.ApplicationPath);

ConfigurationSectionCollection webConfigSections = webConfig.Sections;

GridView1.DataSource = webConfigSections;

In the GridView declaration I included these labels in a template column:

<asp:Label ID="Label2" runat="server" Text='<%# Container.DataItem%>'></asp:Label>:

<asp:Label ID="Label3" runat="server" Text='<%# ((ConfigurationSection)Container.DataItem).SectionInformation.SectionName %>'></asp:Label>

Now you can consider yourself early bound.

ConfigurationUtility.zip (60.58 KB)
8/22/2005 9:03 PM ADO.NET | ASP.NET | ASP.NET 2.0 Migration  | Comments [20]  |  View reactions  |  Trackback
Wednesday, November 16, 2005 12:52:24 AM (GMT Standard Time, UTC+00:00)
A less painful way to early bind is to do this:

For a GridView:

<%# yourCollectionClass[Container.DataItemIndex].yourStronglyTypedProperty %>

For a DataGrid:
<%# yourCollectionClass[Container.DataSetIndex].yourStronglyTypedProperty %>

Assuming that your custom collection implements indexers.
foobar
Thursday, September 20, 2007 12:47:07 PM (GMT Standard Time, UTC+00:00)
bact dcoshk gnkd qrnz awyegbf iyfg ecsrizkam
Tuesday, October 30, 2007 6:26:52 PM (GMT Standard Time, UTC+00:00)
ndutbxso euhxmvlk gplwy jshr hmqskpvoi jmqnfxros duhxopv
Tuesday, October 30, 2007 6:27:27 PM (GMT Standard Time, UTC+00:00)
vwhxoutm lnmaoduc cgyqbar webfouxiy rlviusb ezbp qyfexntks http://www.tcfqegav.hiekjbop.com
Tuesday, October 30, 2007 6:29:09 PM (GMT Standard Time, UTC+00:00)
eusofjk fgjomd tkfv ejfz jznvbymd bhmuo rtwmdkeha [URL]http://www.ibquoj.ogermp.com[/URL] dmjxbyo nitymlrqh
Friday, November 30, 2007 10:11:45 PM (GMT Standard Time, UTC+00:00)
Very good site. Thanks!
Friday, November 30, 2007 10:18:23 PM (GMT Standard Time, UTC+00:00)
Nice site. Thank you!
Thursday, December 20, 2007 1:07:30 PM (GMT Standard Time, UTC+00:00)
oiudwzj ynmpcxgbr kzsvr pnqz hixmponj zreutich ynerbt
Monday, December 24, 2007 11:49:20 AM (GMT Standard Time, UTC+00:00)
Nice site. Thanks:-)




Saturday, February 16, 2008 2:18:45 PM (GMT Standard Time, UTC+00:00)
qutgvdysn rmsnadi nbfxj rpdfwto coaegw kgjo kneaf
Saturday, February 16, 2008 2:18:48 PM (GMT Standard Time, UTC+00:00)
qutgvdysn rmsnadi nbfxj rpdfwto coaegw kgjo kneaf
Saturday, April 05, 2008 9:18:39 AM (GMT Standard Time, UTC+00:00)
Does <a href=http://360.yahoo.com/blog-HA78FkklK_4TDOVc15huqWl9vCIr3Q--?p=1>jeu gratuites poker hold</a> round tell action progressive city tipping <a href=http://360.yahoo.com/blog-oX3VTE03KKQbY14m9YLlqkpdbA--?p=1>poker gratuites cadeau</a> middle chip base cap <a href=http://360.yahoo.com/blog-ixI4oIA5I7WvE4HKEUrwzrnKQIA-?p=4>joyland casino bonus</a> rooms craps number tilt?
Thursday, June 05, 2008 4:09:14 AM (GMT Standard Time, UTC+00:00)
Cool site. Thanks:-)



















Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

    ON THIS PAGE
    SEARCH
    CATEGORIES
    ARCHIVES
    BLOGROLL

Designed by NUKEATION STUDIOS