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 December 5th, 2007, 06:42 AM
Authorized User
 
Join Date: Jul 2006
Posts: 40
Thanks: 1
Thanked 0 Times in 0 Posts
Default Object Data Source parameters

Hi,

I have a details view control which show the data using a static method GetBrochureByID(Just like the Manage Category details view).The ID parameter is taken from a gridview.The problem is when I click the details view insert link button I got the error :

ObjectDataSource 'objBrochure' could not find a non-generic method 'InsertBrochure' that has parameters: Title, bAbstract, Body, ImageUrl, HoverUrl, Abstract.
the Details view code:

Code:
<asp:ObjectDataSource runat="server" ID="objBrochure" TypeName="SANADcompany.BLL.Brochure.Brochure"  InsertMethod="InsertBrochure" UpdateMethod="UpdateBrochure" SelectMethod="GetBrochureByID">
<SelectParameters>
<asp:ControlParameter ControlID="gvwBrochures" PropertyName="SelectedValue" Name="id" Type="Int32" />
</SelectParameters>
<InsertParameters>
<asp:Parameter Name="title" Type="string" />
<asp:Parameter Name="bAbstract" Type="string"/>
<asp:Parameter Name="body" Type="string"/>
<asp:Parameter Name="imageUrl" Type="string"/>
<asp:Parameter Name="hoverUrl" Type="string"/>
</InsertParameters>
<UpdateParameters>
<asp:Parameter Name="id" Type="int32" />
<asp:Parameter Name="title" Type="string" />
<asp:Parameter Name="bAbstract" Type="string"/>
<asp:Parameter Name="body" Type="string"/>
<asp:Parameter Name="imageUrl" Type="string"/>
<asp:Parameter Name="hoverUrl" Type="string"/>
</UpdateParameters>
</asp:ObjectDataSource>
<asp:DetailsView ID="dvwBrochures" runat="server" DataSourceID="objBrochure" DefaultMode="Insert" AutoGenerateRows="false" AutoGenerateEditButton="true" AutoGenerateInsertButton="true" DataKeyNames="ID">
<Fields>
    <asp:BoundField  HeaderText="AddedDate"  InsertVisible="false" DataField="AddedDate" />
    <asp:BoundField HeaderText="Title" DataField="Title" />
    <asp:BoundField HeaderText="Abstract" DataField="Abstract" />
    <asp:BoundField HeaderText="Body" DataField="Body" />
    <asp:BoundField HeaderText="ImageUrl" DataField="ImageUrl" />
    <asp:BoundField HeaderText="HoverUrl" DataField="HoverUrl" />
</Fields>
</asp:DetailsView>
The Insert method code:
Code:
public static int InsertBrochure(string title, string bAbstract, string body, string imageUrl, string hoverUrl)
        {
            BrochureDetails record=new BrochureDetails(0,DateTime.Now,title,bAbstract,body,imageUrl,hoverUrl);
             return SiteProvider.Brochure.InsertBrochure(record);
        }
I have the same problem with the update too.I tried many times but I couldn't solve the problem.I need your help.


 
Old December 5th, 2007, 08:28 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

replace

Code:
<asp:BoundField HeaderText="Abstract" DataField="Abstract" />
for

Code:
<asp:BoundField HeaderText="bAbstract" DataField="bAbstract" />
This should resolve your problem!

 
Old December 6th, 2007, 01:04 AM
Authorized User
 
Join Date: Jul 2006
Posts: 40
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Maxxim
 replace

Code:
<asp:BoundField HeaderText="Abstract" DataField="Abstract" />
for

Code:
<asp:BoundField HeaderText="bAbstract" DataField="bAbstract" />
This should resolve your problem!

This has really solved the insert problem.But I don't understand how does it work.The brochure object property called Abstract not bAbstract as the parameter.The brochure properties are as the following:
Code:
public Brochure(int _Id, DateTime _AddedDate, string _Title, string _Abstract, string _Body, string _ImageUrl, string _HoverUrl)
        {
            ID = _Id;AddedDate = _AddedDate; Title = _Title; Abstract = _Abstract; Body = _Body; ImageUrl = _ImageUrl; HoverUrl = _HoverUrl;
        }
        private int _id=0;
        public int ID
        {
            get { return _id; }
            set { _id = value; }
        }
        private DateTime _addedDate=DateTime.MinValue;
        public DateTime AddedDate
        {
            get
            {
                return _addedDate;
            }
            set
            {
                _addedDate = value;
            }
        }
        private string _title="";
        public string Title
        {
            get { return _title; }
            set { _title = value; }
        }
        private string _abstract="";
        public string Abstract
        {
            get { return _abstract; }
            set { _abstract = value; }
        }
        private string _body="";
        public string Body
        {
            get { return _body; }
            set { _body = value; }
        }
        private string _imageUrl="";
        public string ImageUrl
        {
            get { return _imageUrl; }
            set { _imageUrl = value; }
        }
        private string _hoverUrl="";
        public string HoverUrl
        {
            get { return _hoverUrl; }
            set { _hoverUrl = value; }
        }
 
Old December 6th, 2007, 09:32 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

yes, the brochure object property called Abstract BUT you objDatasource don't look to then!
In your object datasource you have the reference for the insert function:

"InsertBrochure"

And in this function you have:
public static int InsertBrochure(string title, string bAbstract, string body, string imageUrl, string hoverUrl)
        {
            BrochureDetails record=new BrochureDetails(0,DateTime.Now,title,bAbstract,bod y,imageUrl,hoverUrl);
             return SiteProvider.Brochure.InsertBrochure(record);
        }

It will be this value that you datasource will looking for in your detailsview!

Understand now?

 
Old December 7th, 2007, 03:26 AM
Authorized User
 
Join Date: Jul 2006
Posts: 40
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Maxxim
 yes, the brochure object property called Abstract BUT you objDatasource don't look to then!
In your object datasource you have the reference for the insert function:

"InsertBrochure"

And in this function you have:
public static int InsertBrochure(string title, string bAbstract, string body, string imageUrl, string hoverUrl)
        {
            BrochureDetails record=new BrochureDetails(0,DateTime.Now,title,bAbstract,bod y,imageUrl,hoverUrl);
             return SiteProvider.Brochure.InsertBrochure(record);
        }

It will be this value that you datasource will looking for in your detailsview!

Understand now?

So if I give a different name for the update method parameter than the insert method parameter for the same ObjectDataSource for example cAbstract. What should I call the DetailsView DataBound Field bAbstract or cAbstract?.

 
Old December 7th, 2007, 04:53 AM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

If you use different names for your Insert/Update abstract field on you details view... you'll have an error!
unless you specify each of them in your <InsertParameters> and <UpdateParameters>...

But this could be confuse, so... it's a better method use the same names because they represent the same thing!

I don't understand why do you used "bAbstract"... But this forced you to review your code and understand better the objectDatasource!




 
Old December 7th, 2007, 05:48 AM
Authorized User
 
Join Date: Jul 2006
Posts: 40
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Maxxim
 If you use different names for your Insert/Update abstract field on you details view... you'll have an error!
unless you specify each of them in your <InsertParameters> and <UpdateParameters>...

But this could be confuse, so... it's a better method use the same names because they represent the same thing!

I don't understand why do you used "bAbstract"... But this forced you to review your code and understand better the objectDatasource!
As a conclusion :When using Details View DataBound Fields the methods parameters names must be the same name of the DataBoundFields names.Is this conclusion correct?.

Whatever thank you very much for solving this problem for me.I couldn't solve it for along time until you helped me.:)

 
Old December 7th, 2007, 12:58 PM
Friend of Wrox
 
Join Date: Mar 2006
Posts: 310
Thanks: 0
Thanked 0 Times in 0 Posts
Default

hello! Yes, your conclusion is correct!

The objectDatasource is Intermediary

For example, If you want to bind your detailsView -> in your "select" objDatasource you specify the function and the type!
If you specify that you want to bind one brochure, then your objDataSource will find the current brochure from your BLL and will find the right property names in your details view:
        public string Title
        public string Abstract
        public string Body
        public string ImageUrl
        public string HoverUrl

Then, if you want that your details view make one Insert, you specify what is the function from the BLL that makes this insert!
If you want to use the test_function(string aa, string bb, string cc, string dd, string ee){..}
you need to have this boundfields in your details view with this name, because in this way the objDataSource don't call the Brochure Class, just call the test_function and her arguments, and will be this arguments that the objectDataSource will look for in your detailsView...

I hope you understand my bad english!
There are three distinct methods!
In select the objDS find the class
In insert the objDS find the InsertFunction and her arguments and ignore the Brochure class
In update the objDS find the UpdatFunction and her arguments and ignore the Brochure class

You have also the delete method!
Suppose that you specify that your delete function will be: bll.deleteBrochure function (integer myId){...}
To use this you need to specify the dataKeyName for you details view. If you had specify your datakeyname as a simple "ID", you receive an error because the objDS wants to run the funtion and only has: bll.deleteBrochure function (integer myId) ---> There are no information about "ID"



 
Old December 10th, 2007, 12:34 AM
Authorized User
 
Join Date: Jul 2006
Posts: 40
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you for explaining the whole issues:).I expect this will be helpfull for other members too.






Similar Threads
Thread Thread Starter Forum Replies Last Post
Object Data Source class property Colonel Angus ASP.NET 2.0 Professional 5 March 17th, 2008 03:21 PM
Object Data Source error shoakat ASP.NET 2.0 Professional 1 June 20th, 2007 05:40 PM
Object Data Source Error abupapa ASP.NET 2.0 Basics 1 June 13th, 2007 05:43 AM





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