First, add a DetailsView control to the DeclarativeParams. aspx page in the BasicReporting folder. Select <new data source...> from the Smart Tag drop-down list of the DetailsView control, Then add an ObjectDataSource.
Figure 1: add an ObjectDataSource to the page
This will automatically open the configuration data source navigation of the ObjectDataSource control. Select the ProductsBLL class from the navigation bar on the first screen.
Since we want to display information about a specific product, we should use the GetProductByProductID (productID) method.
Figure 3: select the GetProductByProductID (productID) Method
Because we chose this method that contains parameters, the navigation will be one more screen. On this screen, we need to define the values used by parameters. All parameters of the method we specified are displayed in the list on the left. The GetProductByProductID (productID) method has only one parameter: productID. In the parameter source drop-down list on the right, list the types of parameter values that may be used as the parameter source. Since we want to specify a hard-coded value 5 as the productID parameter, let the parameter source option be None and type 5 in the DefaultValue input box.
After the data source Configuration Wizard is complete, the declared tag of the ObjectDataSource control contains a SelectParameters set. The parameters of each method specified in the SelectMethod attribute correspond to a Parameter object. Since the method in this example only requires one parameter parameterID, there is only one element in the SelectParameters set. The SelectParameters set can contain any class from the System. Web. UI. WebControls namespace. The basic Parameter class is used because it is a hard-coded parameter value. If necessary, you can also create a custom Parameter type custom parameter types ).
- < asp:ObjectDataSource ID="ObjectDataSource1" runat="server"
-
- SelectMethod="GetProductByProductID" TypeName="ProductsBLL">
-
- < SelectParameters>
-
- < asp:Parameter DefaultValue="5" Name="productID" Type="Int32" />
-
- < /SelectParameters>
-
- < /asp:ObjectDataSource>
-
Note: If you follow these steps to declare tags on your computer, you may see the parameter values including InsertMethod, UpdateMethod, and DeleteMethod, such as DeleteParameters. The Select data source Wizard of ObjectDataSource automatically specifies these ProductBLL methods for insertion, update, and deletion. Therefore, they will be included in the above tags unless you clear them explicitly.
When you access this page, the Data Web Server Control calls the Select method of ObjectDataSource, which calls the GetProductByProductID (productID) of ProductsBLL class ), use the hard-coded value "5" as the input parameter productID. This method returns a strongly typed ProductDataTable object that contains a product with the ProductID of the Data row Chef Anton's Gumbo Mix Information 5 ).
Hardcoded parameter value: displays information about Chef Anton's Gumbo Mix.
- ASP. NET 2.0 data Tutorial: insert, update, and delete data
- ASP. NET 2.0 data Tutorial: how to add parameterization to the data access layer
- ASP. NET 2.0 data Tutorial: create a data access layer
- ASP. NET 2.0 data Tutorial: create a Web project and configure database connection
- ASP. NET 2.0 data Tutorial: add field-level verification to DataRow