Đang chuẩn bị nút TẢI XUỐNG, xin hãy chờ
Tải xuống
Trong Ví dụ 18,2, điều khiển ObjectDataSource có hai thuộc tính có tên là TypeName và SelectMethod. Các tài sản TypeName chứa tên của các thành phần mà bạn muốn thể hiện với các điều khiển ObjectDataSource. Các tài sản SelectMethod đại diện cho phương pháp của các thành phần mà bạn muốn gọi khi lựa chọn dữ liệu. Việc kiểm soát GridView là ràng buộc để kiểm soát ObjectDataSource thông qua sở hữu DataSourceID của nó. . | 774 CHAPTER 18 Using the ObjectDataSource Control In Listing 18.2 the ObjectDataSource control includes two properties named TypeName and SelectMethod. The TypeName property contains the name of the component that you want to represent with the ObjectDataSource control. The SelectMethod property represents the method of the component that you want to call when selecting data. The GridView control is bound to the ObjectDataSource control through its DataSourcelD property. When you open the page in Listing 18.2 the list of movies is retrieved from the MovieCollection component and displayed in the GridView. The MovieCollection component contains instance methods. The ObjectDataSource automatically creates a new instance of the MovieCollection component before calling its GetMovies method. It automatically destroys the object after it finishes using the object. You also can use the ObjectDataSource control to call shared static methods. In that case the ObjectDataSource doesn t need to instantiate a component before calling the method. Binding to a DataReader Typically you use the ObjectDataSource control to represent database data. The .NET Framework provides you with multiple ways of representing data. This section discusses how you can use an ObjectDataSource to represent a DataReader. NOTE The different ADO.NET objects are compared and contrasted in Chapter 19 Building Data Access Components with ADO.NET. The ADO.NET DataReader object provides you with a fast read-only representation of database data. If you need to retrieve database records in the fastest possible way you should use a DataReader object. For example the component in Listing 18.3 the MovieDataReader component returns all the movies from the Movies database table by using the SqlDataReader object. The component imports the System.Data.SqlClient namespace to use this Microsoft SQL Server-specific ADO.NET object. LISTING 18.3 MovieDataReader.es using System using System.Data using .