Introduction
A common type of report is the master/detail report, in which the report begins by showing some set of "master" records. The user can then drill down into one of the master records, thereby viewing that master record's "details." Master/detail reports are an ideal choice for visualizing one-to-many relationships, such as a report showing all of the categories and then allowing a user to select a particular category and display its associated products. Additionally, master/detail reports are useful for displaying detailed information from particularly "wide" tables (ones that have a lot of columns). For example, the "master" level of a master/detail report might show just the product name and unit price of the products in the database, and drilling down into a particular product would show the additional product fields (category, supplier, quantity per unit, and so on).
There are many ways with which a master/detail report can be implemented. Over this and the next three tutorials we'll look at a variety of master/detail reports. In this tutorial we'll see how to display the master records in a DropDownList control and the details of the selected list item in a GridView. In particular, this tutorial's master/detail report will list category and product information.
Step 1: Displaying the Categories in a DropDownList
Our master/detail report will list the categories in a DropDownList, with the selected list item's products displayed further down in the page in a GridView. The first task ahead of us, then, is to have the categories displayed in a DropDownList. Open the FilterByDropDownList.aspx
page in the Filtering
folder, drag on a DropDownList from the Toolbox onto the page's designer, and set its ID
property to Categories
. Next, click on the Choose Data Source link from the DropDownList's smart tag. This will display the Data Source Configuration wizard.
Choose to add a new ObjectDataSource named CategoriesDataSource
that invokes the CategoriesBLL
class's GetCategories()
method.
After configuring the ObjectDataSource we still need to specify what data source field should be displayed in DropDownList and which one should be associated as the value for the list item. Have the CategoryName
field as the display and CategoryID
as the value for each list item.
At this point we have a DropDownList control that's populated with the records from the Categories
table (all accomplished in about six seconds). Figure 6 shows our progress thus far when viewed through a browser.
Step 2: Adding the Products GridView
That last step in our master/detail report is to list the products associated with the selected category. To accomplish this, add a GridView to the page and create a new ObjectDataSource named productsDataSource
. Have the productsDataSource
control cull its data from the ProductsBLL
class's GetProductsByCategoryID(categoryID)
method.
After choosing this method, the ObjectDataSource wizard prompts us for the value for the method's categoryID
parameter. To use the value of the selected categories
DropDownList item set the Parameter source to Control and the ControlID to Categories
.
Take a moment to check out our progress in a browser. When first visiting the page, those products belong to the selected category (Beverages) are displayed (as shown in Figure 9), but changing the DropDownList doesn't update the data. This is because a postback must occur for the GridView to update. To accomplish this we have two options (neither of which requires writing any code):
-
Set the categories DropDownList's AutoPostBack property to True. (You can accomplish this by checking the Enable AutoPostBack option in the DropDownList's smart tag.) This will trigger a postback whenever the DropDownList's selected item is changed by the user. Therefore, when the user selects a new category from the DropDownList a postback will ensue and the GridView will be updated with the products for the newly selected category. (This is the approach I've used in this tutorial.)
-
Add a Button Web control next to the DropDownList. Set its
Text
property to Refresh or something similar. With this approach, the user will need to select a new category and then click the Button. Clicking the Button will cause a postback and update the GridView to list those products of the selected category.
Figures 9 and 10 illustrate the master/detail report in action.
Adding a "-- Choose a Category --" List Item
When first visiting the FilterByDropDownList.aspx
page the categories DropDownList's first list item (Beverages) is selected by default, showing the beverage products in the GridView. Rather than showing the first category's products, we may want to instead have a DropDownList item selected that says something like, "-- Choose a Category --".
To add a new list item to the DropDownList, go to the Properties window and click on the ellipses in the Items
property. Add a new list item with the Text
"-- Choose a Category --" and the Value
-1
.
Alternatively, you can add the list item by adding the following markup to the DropDownList:
<asp:DropDownList ID="categories" runat="server" AutoPostBack="True" DataSourceID="categoriesDataSource" DataTextField="CategoryName" DataValueField="CategoryID" EnableViewState="False"> <asp:ListItem Value="-1"> -- Choose a Category -- </asp:ListItem> </asp:DropDownList>
Additionally, we need to set the DropDownList control's AppendDataBoundItems
to True because when the categories are bound to the DropDownList from the ObjectDataSource they'll overwrite any manually-added list items if AppendDataBoundItems
isn't True.
Figure 12: Set the AppendDataBoundItems
Property to True
After these changes, when first visiting the page the "-- Choose a Category --" option is selected and no products are displayed.
The reason no products are displayed when because the "-- Choose a Category --" list item is selected is because its value is -1
and there are no products in the database with a CategoryID
of -1
. If this is the behavior you want then you're done at this point! If, however, you want to display all of the categories when the "-- Choose a Category --" list item is selected, return to the ProductsBLL
class and customize the GetProductsByCategoryID(categoryID)
method so that it invokes the GetProducts()
method if the passed in categoryID
parameter is less than zero:
public Northwind.ProductsDataTable GetProductsByCategoryID(int categoryID) { if (categoryID < 0) return GetProducts(); else return Adapter.GetProductsByCategoryID(categoryID); }
The technique used here is similar to the approach we used to display all suppliers back in the Declarative Parameters tutorial, although for this example we're using a value of -1
to indicate that all records should be retrieved as opposed to null
. This is because the categoryID
parameter of the GetProductsByCategoryID(categoryID)
method expects as integer value passed in, whereas in the Declarative Parameters tutorial we were passing in a string input parameter.
Figure 14 shows a screen shot of FilterByDropDownList.aspx
when the "-- Choose a Category --" option is selected. Here, all of the products are displayed by default, and the user can narrow the display by choosing a specific category.
Summary
When displaying hierarchically-related data, it often helps to present the data using master/detail reports, from which the user can start perusing the data from the top of the hierarchy and drill down into details. In this tutorial we examined building a simple master/detail report showing a selected category's products. This was accomplished by using a DropDownList for the list of categories and a GridView for the products belonging to the selected category.
In the next tutorial we'll take the DropDownList interface one step further, using two DropDownLists.
分享到:
相关推荐
动态时空协同过滤 Collaborative Filtering with Temporal Dynamics
Decentralized Quantized Kalman Filtering With Scalable Communication Cost.pdf
an excellent simple introduction to the estimation theory by kalman and bucy
Data scientists and analysts will learn how to perform a wide range of techniques, from writing MapReduce and Spark applications with Python to using advanced modeling and data management with Spark ...
SuRF: Practical Range Query Filtering with Fast Succinct Tries
Adaptive Filtering Primer with Matlab Adaptive Filtering Primer with Matlab Adaptive Filtering Primer with Matlab Adaptive Filtering Primer with Matlab
Third Edition of Kalman Filtering with Real-Time Appli- cations. Interval Kalman Filtering (Chapter 10) is added to ex- pand the capability' of Kalman filtering to uncertain systems, and Wavelet ...
A Tutorial on Particle Filtering and Smoothing.pdf
2013: Working with Data Ranges and Tables is a two-lesson intermediate level course that guides you through organizing, entering and validating worksheet data and then effectively sorting, filtering, ...
classical textbook of Kalman Filtering. With the possible exception of the fast Fourier transform, Kalman filtering is probably the most important algorithmic technique ever devised.
ACC-SO(3)-Constrained Kalman Filtering with Application to Attitude
Data scientists and analysts will learn how to perform a wide range of techniques, from writing MapReduce and Spark applications with Python to using advanced modeling and data management with Spark ...
A Kalman filtering (KF) approach to on-line musical beat tracking with probabilistic data association (PDA) is investigated in this work. We first formulate the beat tracking process as a linear ...
Data Access - Build a Master-Detail Windows Form Data Access - Create an Offline Application Data Access - Custom Data Binding Format Handlers Data Access - Data Entry Form Data Access - How-To Create...
物镜 信息 包裹 物镜 描述 类似于ACL的对象过滤 ...// Filtering a single piece of data filter ( schema , [ 'public' ] , data ) ; // {name: 'Todd'} // Filtering an array of data var mapFn = filt
unknown state of a dynamic system from noisy data taken at discrete real-time. It has been widely used in many areas of industrial and government applications such as video and laser tracking systems,...
Manual for the Matlab toolbox EKF/UKF
A priori knowledge of target detection probability is of critical importance in the Gaussian mixture probability hypothesis density (PHD) and cardinalized PHD (CPHD) filters. In addition, these two...
This tutorial is a worked-out version of a 5-hour course originally held at AIS in September/October 2002. It has two distinct components. First, it contains a mathematically-oriented crash course on ...
使用Python非线性数字滤波:对Python在非线性滤波中的应用进行了详细的介绍,是一份值得学习的资料~