ASP. NET 2.0 data Tutorial: using a hard-coded parameter value

Source: Internet
Author: User

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 ).

 
 
  1. < asp:ObjectDataSource ID="ObjectDataSource1" runat="server" 
  2.  
  3.     SelectMethod="GetProductByProductID" TypeName="ProductsBLL">  
  4.  
  5.     < SelectParameters>  
  6.  
  7.         < asp:Parameter DefaultValue="5" Name="productID" Type="Int32" />  
  8.  
  9.     < /SelectParameters>  
  10.  
  11. < /asp:ObjectDataSource>  
  12.  

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.

  1. ASP. NET 2.0 data Tutorial: insert, update, and delete data
  2. ASP. NET 2.0 data Tutorial: how to add parameterization to the data access layer
  3. ASP. NET 2.0 data Tutorial: create a data access layer
  4. ASP. NET 2.0 data Tutorial: create a Web project and configure database connection
  5. ASP. NET 2.0 data Tutorial: add field-level verification to DataRow

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.