Access data in ObjectDataSource

D

David Thielen

Hi;

I have a page that displays a record and uses an ObjectDataSource to select
the data to be displayed.

How can I get the data it read? I know I can call select() on the object.
But that reads it again and if another user has updated it since the first
read, then I am using data different from what my page is displaying.

So how can I get the data it read to populate the page?
 
D

David Thielen

Hi again;

And how can I tell if the select did get a row - as opposed to no PK passed
in or a PK for a record that no longer exists.
 
P

Phillip Williams

You get the data, that the select method had read:

1- While handling the DataBound event of the control bound to the
ObjectDatasource by accessing the DataItem property

http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.formview.dataitem(VS.80).aspx
http://msdn2.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewrow.dataitem(VS.80).aspx

2- From the Select method if you had set the EnableCaching to true within a
period of seconds that you had specified in the CacheDuration property

http://msdn2.microsoft.com/en-us/li...bcontrols.objectdatasource.select(VS.80).aspx


http://msdn2.microsoft.com/en-us/li...bjectdatasourceselectingeventargs(VS.80).aspx
 
P

Phillip Williams

You can inspect the InputParameters while handling the selected event of the
ObjectDataSource:
http://msdn2.microsoft.com/en-us/li...ntrols.objectdatasource.selecting(VS.80).aspx

You can tell the no. of records that came out during by handling the
Selected event and retrieving the ReturnValue of the ObjectDataSource (which
would be a third option in answering your previous question on how to get the
data that was selected) , e.g.

void odsCustomersList_Selected(object sender,
ObjectDataSourceStatusEventArgs e)
{
lblCount1.Text = "Total Record count= " +
((DataView)e.ReturnValue).Count.ToString();
}

http://msdn2.microsoft.com/en-us/li...ontrols.objectdatasource.selected(VS.80).aspx
 
S

Steven Cheng[MSFT]

Thanks for Phillip's input.

Hi Dave,

In addition to the Selected event Phillipi mentioned, you can also have a
look on the ObjectCreated event:

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

this event fires after the ObjectDatasource control created the underlying
data access object, so if you have some customized methods or properties
on it, you can configure it at that time. Also, this is also a good place
to hold a reference to the underlying data access class object for
sequential use in the page's request.

Hope this also 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.)
 

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
474,430
Messages
2,571,676
Members
48,796
Latest member
Greg L.

Latest Threads

Top