TAILIEUCHUNG - ASP.NET 4 Unleased - p 87
Using the ObjectDataSource Control FIGURE Using the MovieDataSource control to display movies. LISTING Show Movie DataSource From the Library of Wow! eBook Extending the ObjectDataSource Control 835 The custom control must be registered with a directive at the top of Listing . After you register the control, you can simply declare the MovieDataSource | 834 CHAPTER 18 Using the ObjectDataSource Control FIGURE Using the MovieDataSource control to display movies. LISTING @ Page Language C @ Register TagPrefix custom Namespace DOCTYPE html PUBLIC - W3C DTD XHTML EN http TR xhtml11 DTD html xmlns http 1999 xhtml head id Head1 runat server title Show Movie DataSource title head body form id form1 runat server div asp GridView id grdMovies DataSourceID srcMovies Runat server custom MovieDataSource id srcMovies Runat server From the Library of Wow eBook Extending the ObjectDataSource Control 835 div form body html The custom control must be registered with a @ Register directive at the top of Listing . After you register the control you can simply declare the MovieDataSource control in the page to represent the contents of the Movies database table. NOTE As an alternative to registering the MovieDataSource control in a page you can register the control for an entire application in the web configuration file within the pages element. Creating Custom Parameter Objects The standard DataSource Parameter objects included in the Framework enable you to represent objects such as query string values items from Session state and the values of control properties. If none of the standard Parameter objects satisfy your requirements you always have the option of creating a custom Parameter object. You create a custom Parameter object by deriving a new class from the base Parameter class. In this section we create two custom parameters. The first is a UsernameParameter that automatically represents the current username. Next is a PagePropertyParameter that represents the current value of a property contained in the page. Creating a Username Parameter The UsernameParameter class is contained in Listing . The class in Listing derives from the Parameter class and overrides the Evaluate method of the base class. The .
đang nạp các trang xem trước