Business applications commonly employ an encapsulated data model using a middle- tier data access layer or business component. Typically, in a Web application, you must write not only the code for the business data object, but additional code to communicate with the component, and more code to bind controls to the data managed by the component. The ASP.NET data source control model simplifies working with a business component and greatly reduces or eliminates the code you must write by providing the
The ObjectDataSource Control
The ObjectDataSource control works with any business object that encapsulates data and provides data-management services. The ObjectDataSource control uses the standard data source control object model, so that data-bound controls, such as the
You associate an ObjectDataSource control with a business object by setting the ObjectDataSource control's
Once you have associated your ObjectDataSource control with the business object, you can bind a control to the ObjectDataSource control using the data-bound control's
Visual BasicВ | Copy Code |
---|---|
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.VB" Assembly="Samples.AspNet.VB" %> <%@ Page language="vb" %> <html> <head> <title>ObjectDataSource - Visual Basic Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" /> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployees" typename="Samples.AspNet.VB.EmployeeLogic" /> </form> </body> </html> |
C#В | Copy Code |
---|---|
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.CS" Assembly="Samples.AspNet.CS" %> <%@ Page language="c#" %> <html> <head> <title>ObjectDataSource - C# Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" /> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployees" typename="Samples.AspNet.CS.EmployeeLogic" /> </form> </body> </html> |
J#В | Copy Code |
---|---|
<%@ Register TagPrefix="aspSample" Namespace="Samples.AspNet.JSL" Assembly="Samples.AspNet.JSL" %> <%@ Page language="VJ#" %> <html> <head> <title>ObjectDataSource - VJ# Example</title> </head> <body> <form id="Form1" method="post" runat="server"> <asp:gridview id="GridView1" runat="server" datasourceid="ObjectDataSource1" /> <asp:objectdatasource id="ObjectDataSource1" runat="server" selectmethod="GetAllEmployees" typename="Samples.AspNet.JSL.EmployeeLogic" /> </form> </body> </html> |
For more details, see the topics in the ObjectDataSource Web Server Control section.