Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How ASP.NET 2.0 data uses a hard-coded parameter value

2025-01-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

Today, I will talk to you about how to use a hard-coded parameter value for ASP.NET 2.0 data, which may not be well understood by many people. in order to make you understand better, the editor has summarized the following content for you. I hope you can get something according to this article.

For examples of using hard-coded parameter values in ASP.NET 2.0, first add a DetailsView control to the DeclarativeParams.aspx page in the BasicReporting folder. Select from the drop-down list of smart tags in the DetailsView control

< 新建数据源…>

And then choose to add an ObjectDataSource

Figure 1: adding an ObjectDataSource to the page

This automatically opens the configuration data source navigation for the ObjectDataSource control. Select the class ProductsBLL in the navigation of the * * 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, there is an extra screen for navigation, where we are required to define the values used by the parameters. Display all the parameters of the method we specified in the list on the left. For the GetProductByProductID (productID) method, there is only one parameter: productID. Several types of parameter values that may be used as parameter sources are listed in the parameter source drop-down list on the right. Since we want to specify a hard-coded value of 5 as the productID parameter, let the parameter source option be None and type 5 in the DefaultValue input box.

After completing the configure data source wizard, the declaration tag of the ObjectDataSource control contains a SelectParameters collection, and the parameters of each method specified in the SelectMethod property correspond to a Parameter object. Since the method in our example requires only one parameter parameterID, there is only one element in the SelectParameters collection. The SelectParameters collection can contain any class derived from the System.Web.UI.WebControls namespace. Use the basic Parameter class because it is a hard-coded parameter value; you can also create a custom parameter type (custom parameter types) if necessary.

< 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 step declaration tags on your computer, you may see that there are parameter values for InsertMethod,UpdateMethod and DeleteMethod, such as DeleteParameters. ObjectDataSource's Select data Source wizard automatically specifies the methods of these ProductBLL to implement inserts, updates, and deletions, so unless you explicitly clear them, they will be included in the tags above.

When visiting this page, the Data Web server control will call the Select method of ObjectDataSource, which will call GetProductByProductID (productID) of class ProductsBLL and use the hard-coded value of "5" as the input parameter productID. This method returns a strongly typed ProductDataTable object that contains information about a data row-Chef Anton's Gumbo Mix (a product with a ProductID of 5).

Hard-coded parameter values: displays information about Chef Anton's Gumbo Mix

After reading the above, do you have any further understanding of how ASP.NET 2.0 data uses a hard-coded parameter value? If you want to know more knowledge or related content, please follow the industry information channel, thank you for your support.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report