Click to Rate and Give Feedback
Collapse All/Expand All Collapse All
This page is specific to
Microsoft Visual Studio 2008/.NET Framework 3.5

Other versions are also available for the following:
ASP.NET
ObjectDataSource Web Server Control Overview

Updated: July 2009

The ASP.NET ObjectDataSource control represents a middle-tier object with data retrieval and update capabilities. The ObjectDataSource control acts as a data interface for data-bound controls such as the GridView, FormView, or DetailsView controls. You can use these controls to display and edit data from a middle-tier business object on an ASP.NET Web page.

This topic contains:

Most ASP.NET data source controls, such as the SqlDataSource, are used in a two-tier application architecture where the presentation layer (the ASP.NET Web page) communicates directly with the data tier (the database, an XML file, and so on). However, a common application design practice is to separate the presentation layer from business logic and encapsulate the business logic in business objects. These business objects form a layer between the presentation layer and the data tier, resulting in a three-tier application architecture. The ObjectDataSource control supports a three-tier architecture by providing a way for you to bind data controls on the page to a middle-tier business object. The ObjectDataSource works with a middle-tier business object to select, insert, update, delete, page, sort, cache, and filter data declaratively without extensive code.

The ObjectDataSource control uses reflection to call methods of a business object to select, update, insert, and delete data. You set the ObjectDataSource control's TypeName property to specify the name of the class to use as a source object. For details on how to create a source data object to be used with the ObjectDataSource control, see Creating an ObjectDataSource Control Source Object.

Sorting and Paging

The ObjectDataSource control can support additional sorting and paging capabilities by passing sort and page information in requests from a data-bound control, such as a GridView control, to the data object for processing. The source data object or the data source control itself can then sort data and return data in pages.

For information on passing sorting and paging parameters to an ObjectDataSource control's data object, see Using Parameters with the ObjectDataSource Control.

Updating

When you use the ObjectDataSource class to update or insert data, strings that are entered at the client are not automatically converted from the client culture format to the server culture format. For example, the client culture might specify DD/MM/YYYY as the date format, and the date format on the server might be MM/DD/YYYY. In that case, October 5, 2009 would be entered in a TextBox control as 5/10/2009 but would be interpreted as May 10, 2009. October 15, 2009 would be entered as 15/10/2009, and would be rejected as an invalid date.

Caching

The ObjectDataSource control can cache objects returned by the underlying business object. However, you should not cache objects that hold resources or that maintain state that cannot be shared among multiple requests, such as an open DataReader object.

Filtering

If the object returned to the ObjectDataSource control by the source data object is a DataSet or DataTable object, the ObjectDataSource control supports filtering using the syntax of the Expression property of the DataColumn class. Filtering enables you to expose only rows that match particular search criteria, without having to re-query the data source with new selection criteria. For more information, see Filtering Data Using Data Source Controls.

Conflict Detection

By setting the ObjectDataSource control's ConflictDetection property to true, you can specify that the ObjectDataSource control should include original values when calling update methods of the source data object. The original values can then be included in checks for optimistic concurrency. For more information, see Using Parameters with the ObjectDataSource Control. For information on optimistic concurrency checking, see Optimistic Concurrency (ADO.NET).

Back to top

The following table lists the key classes that relate to the ObjectDataSource control.

Member

Description

ObjectDataSource

The main class for the control.

Back to top

Date

History

Reason

July 2009

Added a section about Updating culture-variant strings.

Customer feedback.

Tags What's this?: Add a tag
Community Content   What is Community Content?
Add new content RSS  Annotations
ObjectDataSource does not correctly handle data in culture-specific format      romario3   |   Edit   |   Show History
ObjectDataSource does not correctly handle data in culture-specific format, for more information see this bug: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=105016
Tags What's this?: Add a tag
Flag as ContentBug
ObjectDataSoure does not seem to support extension methods of an object.      Gil.Y   |   Edit   |   Show History

There are times when we want to work with single object, ODS does not seem to support that.
The recent addition of extension method might be a good solution to this situation as it is easy to extent another method to the object only in the context of working with ODS from the ASP.NET project.
To my supprise ODS "Wizard" does not recognize extension methods at all.
So now I have no alternative than adding a method that returns a list of my objects inside my BLL when what I really need is a single object, this technique is dirty since that method is only going to be used in GUI context with the ODS.

Whoever responisble to the development of ODS: Either allow ODS to work with single objects as well or add to the ODS the required support to recognize extension methods.
Not doing both forces everyone to work incorrect.

Processing
© 2009 Microsoft Corporation. All rights reserved. Terms of Use | Trademarks | Privacy Statement | Site Feedback
Page view tracker