Get cached value returned from Select()

D

David Thielen

Hi;

In my code-behind, is there a way to get the data returned from the Select()
call from an ObjectDataSource? I know I can call it again, but when the page
is first created ASP has already called it to populate controls and I would
prefer to not call it twice.

Also, is there a way to find out if the last call to Select() actually
returned a row of data? In other words, if the page is displaying
<EmptyDataTemplate> I would like to know that in my code-behind.
 
S

Steven Cheng[MSFT]

Hi Dave,

Thank you for posting.

As for ObjectDataSource control, we can use the Selected Event to get the
Data Object returned by its internall Select operation. This event fire
after the internal data access class instance has selected and returned the
data object(e.g DataSet or DataTable...). e.g:

====================
protected void ObjectDataSource1_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
Response.Write("<br/>" + e.ReturnValue.GetType());
}
========================

#ObjectDataSource.Selected Event
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdat
asource.selected(VS.80).aspx


Also, if the data access object use instance method as Select method, the
runtime will create an instance of the Data Access class, thus, we can
access that Data Access class's instance through the "ObjectCreated" event,
then if have defined some internal property and method on the Data Access
class for cache and get the cached data object, we can access it through
the object obtained in the "ObjectCreated" event:

protected void ObjectDataSource1_ObjectCreated(object sender,
ObjectDataSourceEventArgs e)
{

Response.Write("<br/>" + e.ObjectInstance.GetType());
}


#ObjectDataSource.ObjectCreated Event
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.objectdat
asource.objectcreated(VS.80).aspx


Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
S

Steven Cheng[MSFT]

You're welcome Dave,

Best Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,763
Messages
2,569,563
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top