Add the GridView to the page in ASP. NET 2.0

Source: Internet
Author: User

Add SupplierListMaster. aspx and ProductsForSupplierDetails. after the aspx, the following is the SupplierListMaster. create a GridView that displays the supplier on the aspx page. add a GridView to the page and bind it to a new ObjectDataSource. This ObjectDataSource should use the getsuppliersbll class () method to return all vendors.

 

Add GridView: Select SuppliersBLL class

 

Add a GridView: Configure ObjectDataSource to use the GetSuppliers () method

We need to include a "view product" link in each GridView line. When we click this link, it will go to ProductsForSupplierDetails. on the aspx page, pass the SupplierID value of the selected row in the query string (querystring. for example, if you click the "view product" link of the supplier Tokyo Traders (SupplierID is 4), it will be forwarded to ProductsForSupplierDetails. aspx? SupplierID = 4.

To implement this function, add a HyperLinkField column to the GridView, which adds a link for each row in the GridView. click Edit column link on the GridView Smart Tag. select HyperLinkField from the list in the upper left corner and click Add to add HyperLinkField to the field list of the GridView.

 

Add a GridView: Add a HyperLinkField to the GridView

HyperLinkField can be configured to use the same text or URL values in each GridView row, or to bind these values to the data values of a Specific Row. to specify a static value with the same values for all rows, use the Text or NavigateUrl attribute of HyperLinkField. because we want to make the link Text of each line consistent, set the Text attribute of HyperLinkField to "view product ".

 

Add a GridView: Set the Text attribute of HyperLinkField to "view product"

To bind text or URL to the underlying data of the row in the GridView, you may use DataTextField or DataNavigateUrlFields to specify the data field from which Text or URL is to be obtained. dataNavigateUrlFields can only be set as a single data field. DataNavigateUrlFields can be set as a list of data fields separated by commas. we need to make TEXT or URL Based on the Data Field Values and some tags of the current row. for example, in this tutorial, we want the URL of HyperLinkField to be ProductsForSupplierDetails. aspx? SupplierID = supplierID. Where supplierID is the supplierID value of each row of the GridView. Note that we need static values and data driver values. ProductsForSupplierDetails. aspx? SupplierID = this part is a static value, while supplierID is data-driven, and its value is the SupplierID value of each row.

To specify a mixture of the static value and data driver value, use the extextformatstring and DataNavigateUrlFormatString attributes. enter static text as needed in these attributes and use {0} to display specific fields in the extextfield or DataNavigateUrlFields attribute. if DataNavigateUrlFields has multiple fields, use {0} when the first field is required, use {1} For the second field, and so on.

For this tutorial, we need to set DataNavigateUrlFields to SupplierID, because we need to use this data field to customize the link of each row.

 

Add a GridView: Configure HyperLinkField to use a SupplierID-based link address.

After HyperLinkField is added, you can customize and re-arrange the fields in the GridView. below is the modified mark (markup ):

Access SupplierListMaster in the browser. aspx. 7. All suppliers are listed on the page. Each Vendor contains the "view product" link. click "view product" to go to ProductsForSupplierDetails. aspx, and pass the supplier's SupplierID value in the query string.

 

Add a GridView: each vendor contains the "view product" link.

  1. ASP. NET 2.0 data Tutorial: Add An aspx page to a site
  2. ASP. NET 2.0 data Tutorial: Create a master page
  3. ASP. NET cross-page value passing skills
  4. ASP. NET 2.0 data Tutorial: add custom encoding to DAL
  5. ASP. NET 2.0 data Tutorial: completes the data access layer

Related Article

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.