Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 25th, 2008, 05:06 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default Category BLL/UI Problem

I'm following the code in the book, and have reached chapter 5, News and Article Management. Implementing the GridView/DetailsView in ManageCategories.aspx. I get the following exception when I try to update a category:

Code:
[InvalidOperationException: ObjectDataSource 'objCurrentCategory' could not find a non-generic method 'UpdateCategory' that has parameters: Title, Importance, ImageUrl, Description.]
   System.Web.UI.WebControls.ObjectDataSourceView.GetResolvedMethodData(Type type, String methodName, IDictionary allParameters, DataSourceOperation operation) +1440
   System.Web.UI.WebControls.ObjectDataSourceView.ExecuteUpdate(IDictionary keys, IDictionary values, IDictionary oldValues) +2292
   System.Web.UI.DataSourceView.Update(IDictionary keys, IDictionary values, IDictionary oldValues, DataSourceViewOperationCallback callback) +179
   System.Web.UI.WebControls.DetailsView.HandleUpdate(String commandArg, Boolean causesValidation) +1199
   System.Web.UI.WebControls.DetailsView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +545
   System.Web.UI.WebControls.DetailsView.OnBubbleEvent(Object source, EventArgs e) +163
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
   System.Web.UI.WebControls.DetailsViewRow.OnBubbleEvent(Object source, EventArgs e) +118
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +56
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +106
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +175
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +31
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +32
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +244
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3836
I checked the method signature of MB.TheBeerHouse.BLL.Articles.Category.UpdateCatego ry() and it is the same as Marco's in the downloaded code.

Anybody have an idea of what could going wrong here?
  #2 (permalink)  
Old November 25th, 2008, 05:26 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

This is because UpdateCategory takes five parameters -- title, importance, description, imageUrl, and id.

If you don't pass the id, how would the database know which category to update, right? ;)

I suspect that you may have forgotten to specify DataKeyNames="ID" in the DetailsView.

_________________________________

Visit my blog at http://leedumond.com
  #3 (permalink)  
Old November 25th, 2008, 05:44 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It was exactly that. When I added the DataKeyNames attribute it worked just fine. I'm kinda fascinated by the magic of ASP.NET 2.0, especially with ObjectDataSources and how they automatically work with the GridView and DetailsView.

A couple of more questions on the code, though: Why are SortExpression attributes being used in the DetailsView? And I'm assuming that the InsertVisible attribute on BoundFields excludes them from the insertion operation. Am I correct?
  #4 (permalink)  
Old November 25th, 2008, 06:25 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

Quote:
quote:Originally posted by mashour
 It was exactly that. When I added the DataKeyNames attribute it worked just fine. I'm kinda fascinated by the magic of ASP.NET 2.0, especially with ObjectDataSources and how they automatically work with the GridView and DetailsView.
That's reflection. The ObjectDataSource uses reflection on your type to figure out the method signatures at runtime. Pretty cool actually.

Quote:
quote:Originally posted by mashour


A couple of more questions on the code, though: Why are SortExpression attributes being used in the DetailsView? And I'm assuming that the InsertVisible attribute on BoundFields excludes them from the insertion operation. Am I correct?
Question 1: Very perceptive. SortExpressions are useful when you've implemented paging on your DetailsView. Since this doesn't apply here, the SortExpression property serves no purpose. But since they're usually added automatically when you configure the DetailsView in the designer, I suspect Marco just left them in there. No harm either way.

Question 2: InsertVisible="False" is used to indicate that you don't want a boundfield to show when the DetailsView is in Insert mode. It doesn't necessarily exclude a field from the insert operation, but it does prevent a user from supplying that data. Here, you wouldn't want the user to supply an ID (the database will do that) or the AddedBy (this field is set to the current user in code).

_________________________________

Visit my blog at http://leedumond.com
  #5 (permalink)  
Old November 25th, 2008, 06:32 PM
Authorized User
 
Join Date: Nov 2008
Location: , , .
Posts: 12
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Lee!
 


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Separation between ui and bll flowjob BOOK: ASP.NET 2.0 Website Programming Problem Design Solution ISBN: 978-0-7645-8464-0 3 July 11th, 2007 08:55 AM
Add category on Blog highspeedwire BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 3 January 26th, 2007 05:35 PM
problem with UI Webcontrol-treeview hawing General .NET 1 December 30th, 2004 11:19 AM
Need help with creating a Parent Category seanmayhew BOOK: ASP.NET Website Programming Problem-Design-Solution 2 November 13th, 2004 06:20 PM
Listing Category then Items harpua Classic ASP Professional 3 December 12th, 2003 11:47 AM



All times are GMT -4. The time now is 09:53 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.