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 July 3rd, 2009, 04:42 AM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Unhappy How to get value form BLL to Form View

Could you please help me, I would like to know about developing program by MVC.
(User Interface, Business Logic Layer, Data Access Layer)
According to Data from Form View can collect into database,
so I create ID for use in next screen.
This process should operate before write in database by Business Logic.
However, it was not work because data did not send to User Interface using FormView.
Acutally, I have InsertSomething method for collect data to database responsible for keep log and create new ID.
This method is in MB.SomeNameSpace.BLL.SomeClass

My example code :

Code (ASP)
HTML Code:
01.<%
02....
03.<asp:FormView ID="FormView1" runat="server" DataKeyNames="ProjectID" DataSourceID="ODS1"
04.        DefaultMode="Insert" OnItemInserted="FormView1_ItemInserted">
05. 
06. ... Other Template ...
07. 
08.</asp:FormView>
09.<asp:objectDataSource ID="ODS1" runat="server" InsertMethod="InsertSomething" SelectMethod="GetSomething"
10. 
11.TypeName="MB.SomeNameSpace.BLL.SomeClass.SomeInsertMethod">
12.<SelectParameters>
13.     <asp:QueryStringParameter DefaultValue="0" Name="FieldID" Type="String" />
14.</SelectParameters>
15.<InsertParameters>
16.       <asp:Parameter Name="FieldID" Type="String" Direction="ReturnValue" />
17.       <asp:Parameter .....>
18.</InsertParameters>
19.%>
Code behind (C#)
Code:
01.protected void Page_Load(object sender, EventArgs e)
02.{
03.}
04.protected void FormView1_ItemInserted(object sender, FormViewInsertedEventArgs e)
05.{
06. FormView1.ChangeMode(FormViewMode.ReadOnly);      // it not work
07.FormView1.DataBind();  // Still not work too
08.     
09.      // How to get ID when item inserted
10.}
Business Logic Layer Code (C#)
Code:
01.namespace MB.SomeNameSpace.BLL
02.{
03. public class SomeClass : SomeBaseClass
04. {
05.    ....
06. }
07. public static String InsertSomething(SomeParam, ..., ...)
08. {
09.    NewID = SiteProvider.SomeClass.MakeNewID(bySomeCode);    
10.    SomeDetails record = new SomeDetails(SomeParam, ..., ...);  
11.    bool ret = SiteProvider.SomeClass.InsertProject(record);    
12.   if(ret) {
13.        DoMyBussinessSomething();
14.      // Here, NewID Has value
15.    return NewID;
16.  } else {
17.     String.Empty;
18.  }
19.    }
20.}
 
Old July 3rd, 2009, 05:16 PM
Authorized User
 
Join Date: Mar 2009
Posts: 75
Thanks: 16
Thanked 1 Time in 1 Post
Default

Hi,
I couldn't understand from your post what exactly you are trying to do.

But I guess you are trying to get back the generated value that is returned by the Stored Procedure?
If I take BeerHouse as an example, you want to get the ID of the Inserted Comment (article, category and etc)?

If this is so, one way to do it is:
First to remove
<asp:Parameter Name="FieldID" Type="String" Direction="ReturnValue" />
from the objectatasource , then simply add to "Inserted" event to the objectatasource and from there get the returned value:

int x = (int)e.ReturnValue;

(where e is ObjectDataSourceStatusEventArgs )

If this is not what you want please tell.

Last edited by yevi; July 3rd, 2009 at 05:18 PM..
The Following User Says Thank You to yevi For This Useful Post:
nitis (July 5th, 2009)
 
Old July 5th, 2009, 03:20 AM
Registered User
 
Join Date: Jul 2009
Posts: 2
Thanks: 1
Thanked 0 Times in 0 Posts
Default

Thank you so much for your suggestion.

Fix in ASP
<asp:objectDataSource ID="ODS1" runat="server" InsertMethod="InsertSomething" SelectMethod="GetSomething"
OnItemInserted="ODS1_ItemInserted">

Fix in Code Behide
protectedvoid ODS1_Inserted(object sender, ObjectDataSourceStatusEventArgs e)
{
if (e.ReturnValue != null)
{
ViewState[
"ID"] = e.ReturnValue.ToString();
...
...
}
}

Last edited by nitis; July 5th, 2009 at 03:36 AM..





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to view picture by using form view? mysecondlove ASP.NET 2.0 Basics 1 April 8th, 2008 07:17 AM
Form View in User Control shoakat ASP.NET 2.0 Professional 0 June 20th, 2007 07:29 AM
View an ado recordset in a form feets Access VBA 5 June 20th, 2007 06:19 AM
Form View Controls Unaccessable Mehranian ASP.NET 2.0 Professional 1 May 21st, 2006 04:02 PM
Resizing of form view - problem lmadhavi Visual C++ 2 October 1st, 2004 06:18 AM





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