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 September 3rd, 2009, 06:22 PM
Registered User
 
Join Date: Aug 2009
Posts: 7
Thanks: 2
Thanked 0 Times in 0 Posts
Default Can anybody please 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, 10:30 PM
Lee Dumond's Avatar
Wrox Author
 
Join Date: Jan 2008
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Eval always returns a string. So, when we are using Eval to set a text property, no cast is necessary, because the Text property of a control takes a string.

However, the Visible property of a control takes a boolean value. Eval("Approved") returns either the string "true" or the string "false". Therefore, that string output must be cast to a bool in order to use it to set the Visible property.

In this case, the string "true" would be cast to the Boolean value TRUE, and the string "false" would be cast to the Boolean value FALSE.
__________________
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 (September 3rd, 2009)









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