Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
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
  #1 (permalink)  
Old October 13th, 2009, 02:20 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default Author claims default value can’t be set declaratively

hi

On page 247 we handle dvwCategory’s ItemCreated event, and if the control is in insert mode, we get a reference to the textbox for the Importance field and set its default value to 0. Author claims default value can’t be set declaratively and for that reason we needed to handle dvwCategory’s ItemCreated event.

a) But as far as I know, if dvwCategory had InsertItemTemplate column defined, then we could set default value declaratively? If my assumption is correct, then why didn't author choose that option instead?

thanx
  #2 (permalink)  
Old October 13th, 2009, 05:20 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You are technically correct that the Importance textbox could be set declaratively by doing this:

Code:
<InsertItemTemplate>
   <asp:TextBox ID="txtImportance" runat="server" Text="0" MaxLength="256" Width="100%"></asp:TextBox>
</InsertItemTemplate>
However, that wouldn't work if we want this field to participate in the update, because there're no databinding expression.

If you actually try this, the ObjectDataSource will throw an InvalidOperationException:

ObjectDataSource 'objCurrCategory' could not find a non-generic method 'InsertCategory' that has parameters: Title, ImageUrl, Description.

It is the Bind expression that let's a value participate in the two-way dayabinding process. If you try to set the Importance field declaratively, without a Bind expression, it cannot participate as a parameter in the two-way databinding. Therefore, it never gets sent as a parameter to the InsertCategory method.
__________________
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:
carewithl (October 14th, 2009)
  #3 (permalink)  
Old October 14th, 2009, 01:22 PM
Authorized User
 
Join Date: Jun 2009
Posts: 32
Thanks: 17
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by Lee Dumond View Post
You are technically correct that the Importance textbox could be set declaratively by doing this:

Code:
<InsertItemTemplate>
   <asp:TextBox ID="txtImportance" runat="server" Text="0" MaxLength="256" Width="100%"></asp:TextBox>
</InsertItemTemplate>
However, that wouldn't work if we want this field to participate in the update, because there're no databinding expression.

If you actually try this, the ObjectDataSource will throw an InvalidOperationException:

ObjectDataSource 'objCurrCategory' could not find a non-generic method 'InsertCategory' that has parameters: Title, ImageUrl, Description.

It is the Bind expression that let's a value participate in the two-way dayabinding process. If you try to set the Importance field declaratively, without a Bind expression, it cannot participate as a parameter in the two-way databinding. Therefore, it never gets sent as a parameter to the InsertCategory method.
Uh, I can’t believe I’ve missed that one. Sorry for taking you time and thank you


Similar Threads
Thread Thread Starter Forum Replies Last Post
Author claims ObjectDataSource is bound to data source before Page_Load and not after carewithl BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 2 August 13th, 2009 02:20 PM
how do i set default parameter value.. rupen Classic ASP Basics 5 January 5th, 2007 12:14 AM
XMLDOM default character set sonicDace XML 0 May 21st, 2004 03:09 PM
how to set parameter default value oranginalab Classic ASP Basics 0 August 28th, 2003 02:53 AM





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