Wrox Programmer Forums
|
BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0
This is the forum to discuss the Wrox book ASP.NET 2.0 Website Programming: Problem - Design - Solution by Marco Bellinaso; ISBN: 9780764584640
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 23rd, 2009, 10:51 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Need some clarification

Hi I am new to ASP.NET and am on chapter 4 of this book.I am stumbled upon a few things..Can anyone help?


1.The data binding expression that is used inside the repeater control
Text='(%#Container.DataItem%)' and CommandArgument= '(%#Container.DataItem%)' . Why are we using this syntax?
I am fammiliar with the data binding expressions for a formview control like the Eval (%#) and the other one used for two way data binding.

So the one he used with repeater control is same as those?
 
Old August 24th, 2009, 05:00 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Container.DataItem is an alias for a specific item in a bound list. The actual type of DataItem is determined by the type of the datasource. Since in this case the datasource is an array of strings, when Container.DataItem is evaluated at runtime, you get strings.

This works perfectly well, but using Container.DataItem is sometimes a pain because the expression syntax varies based on the type. For example, if you are binding to a collection of Customer objects instead of an array of strings, and you want to display the customer’s names in a repeater, you’d do this:

<%# ((Customer)Container.DataItem).CustomerName %>

In order to alleviate the confusing type-based syntax, the Databinder.Eval method was invented, so to bind to the Customer collection in the above example, you could do this instead:

<%# DataBinder.Eval(Container.DataItem, “CustomerName” %>

Databinder.Eval uses reflection to determine the type represented by Container.DataItem, and works out the syntax accordingly.

Subsequent revisions in the framework let you leave off the DataBinder part. If the data type to which you are binding is known, such as a row in a GridView Control, you can also omit the Container.DataItem call:

<%# Eval(“CustomerName”) %>

However, since in this case the repeater only binds to an array of strings, there is no benefit to using the Eval method here. By simply using Container.DataItem to bind to members of a string array, the syntax is simpler and you don’t take the hit from the use of reflection employed by Eval.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
The Following User Says Thank You to Lee Dumond For This Useful Post:
rennishj (August 24th, 2009)
 
Old August 24th, 2009, 11:46 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default

Thank You so much for the quick reply
 
Old September 3rd, 2009, 05:53 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Can anyone help?

I am on chapter 5 of this book. I am having problem understanding the databinding Expression . I know that you can use Eval() when you know the datatype of the item to be bound.The problem is on the ArticleListing.ascx markup

Could anyone explain why he is casting the expression
Visible='<%#(bool)Eval("Approved")>' to bool(Because it is coming from the Articles table and the Approved is a bit field in that table).

I dont know whether am undestanding that correctly. For a label how can we set the Text=<%#Eval("ReleaseDate","{0:d}")> to a formatted datetime field? Why we dont need any casting here?


Any help would be greatly appreciated

Thank You
 
Old September 3rd, 2009, 06:15 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

It can be difficult to follow things when you post multiple questions to the same thread.

As this is a different question from the one originally asked, I woud suggest posting it into a new thread.

You are also likely to get a faster answer that way.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}





Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl clarification... rajesh_css XSLT 1 October 2nd, 2008 01:56 AM
STL's clarification sspr C++ Programming 1 February 23rd, 2006 04:43 AM
clarification in xslt rameshnarayan XSLT 0 August 23rd, 2005 02:28 AM
Clarification on Namespace sathya.n XML 1 March 2nd, 2005 10:24 AM
design issue(clarification) eyan C# 0 February 19th, 2004 12:42 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.