|
 |
ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional 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 .
|
 |
|
|

March 17th, 2008, 10:35 AM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Object Data Source class property
I am having difficulty assigning a property to be used in an ObjectDataSource SELECT method. I am able to set the parameters to match my method signature properly with no problem.
However, my method also uses an object public property - it is not part of the method signature. How am I able to set this public property and have it consumed by the method call?
It's like this:
Public Class myClass
Public Property myProp() As String
Get
Return m_myProp
End Get
Set(ByVal Value As String)
m_myProp = Value
End Set
End Property
Public Function GetData(myParam1 as Integer, myParam2 as String) as DataSet
dim ds as DataSet
.
.
If m_myProp = 1 Then
'do something
End If
.
return ds
End Function
Is my only option to change the method signature?
Thanks in advance for your comments.
|

March 17th, 2008, 11:49 AM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Hi there,
Take a look here: http://imar.spaanjaars.com/QuickDocId.aspx?quickdoc=368 and look at method #3 in particular. It shows you how to create a new instance of your business object, set the necessary properties and then let the ODS figure out the rest.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|

March 17th, 2008, 11:56 AM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Imar-
Funny you mention that. I took a look at it before I posted. I'm still not sure how you tie that OnCreated method to the method call.
|

March 17th, 2008, 12:05 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
First you need to write code for the ObjectCreating event of the ODS, like this:
Code:
Protected Sub ObjectDataSource1_ObjectCreating(ByVal sender As Object, _
ByVal e As System.Web.UI.WebControls.ObjectDataSourceEventArgs) _
Handles ObjectDataSource1.ObjectCreating
Dim myInstance As New MyClass()
myInstance.myProp = "Whatever value you need here"
e.ObjectInstance = myInstance
End Sub
That way, an instance of your business object is created when the ODS is about to call your method.
Next, within your method, you should be able to retrieve the myProp property (using m_myprop or myProp) and get at the value you set in the ObjectCreating event in the page.
Hope this helps,
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|

March 17th, 2008, 02:02 PM
|
Friend of Wrox
|
|
Join Date: Oct 2003
Location: Albany, NY, USA.
Posts: 218
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
That did the trick. I can now send my value to the object method.
Dank U Imar
|

March 17th, 2008, 03:21 PM
|
 |
Wrox Author
Points: 72,055, Level: 100 |
|
|
Join Date: Jun 2003
Location: Utrecht, Netherlands.
Posts: 17,086
Thanks: 80
Thanked 1,587 Times in 1,563 Posts
|
|
Graag gedaan... ;)
Imar
---------------------------------------
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Everyone is unique, except for me.
Author of Beginning ASP.NET 3.5 : in C# and VB, ASP.NET 2.0 Instant Results and Dreamweaver MX 2004
Want to be my colleague? Then check out this post.
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |