Asp.net2.0 using GridView to realize master-slave relationship

Source: Internet
Author: User
Tags bind

First, let's look at how to implement a Master-detail master-slave relationship using the GridView to achieve a one-to-many relationship, as this is a very popular web application. In ASP.net 1.1, it is possible to write more code to implement such an application, but in ASP.net 2.0, it is easy to implement such a master-slave relationship. Here's a step-by-step introduction to:

We introduce the Northwind database in SQL Server 2000 as an example. There are many examples of one-to-many relationships in the database. Here, we introduce the Products table and order Detail table. Among them, we realize such an application, through the DropDownList Drop-down box, when the user selects one kind of goods each time, may immediately through the GridView display in all orders, which order has ordered the product, two tables constitute the typical one-to-many relationship.

First, we take the product out of the product table and bind it to the DropDownList. We drag a SqlDataSource control to the form, name it Productlistingdatasource, and then set the Productid,productname field out of the product table, And sort by ProductName, then drag a DropDownList control into the form, click the smart tag smart tag for the control, and in the pop-up menu, select Data Source as The name of the SqlDataSource you just added (that is, Productlistingdatasource) and select ProductName as the text to display in the Drop-down box, and to set the Prodcutid to the selected value of the Drop-down box. As shown in the following illustration:

Next, we drag a SqlDataSource control into the form, named Orderdetailsforproduct, in which we bind it to the Order Detail table, because we don't need to return all the fields. So we just need to go back to Orderid,unitprice and quantity three fields, and we need to be associated with DropDownList, so we're going to set up the appropriate SQL statements. In asp.net 2.0, this can also be achieved through the operation of the menu.

When we set the SqlDataSource property, we click the Where button when we encounter the steps shown in the following figure.

After the "where" button is clicked, in the pop-up menu (shown below), set column to ProductID, set the operator operator to "=", set the value of the source Drop-down box to be bound to the value from the control, and then select And then on the right Parameter Properties window, the Conrol ID is set to the name of the DropDownList control name that we added just now, and finally, remember to press the "Add" button so that the SQL statement is set up.

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.