外文翻译 英文文献 使用两个DropDownList过滤的主从报表.docx
《外文翻译 英文文献 使用两个DropDownList过滤的主从报表.docx》由会员分享,可在线阅读,更多相关《外文翻译 英文文献 使用两个DropDownList过滤的主从报表.docx(25页珍藏版)》请在冰豆网上搜索。
![外文翻译 英文文献 使用两个DropDownList过滤的主从报表.docx](https://file1.bdocx.com/fileroot1/2022-10/24/46da51d9-2928-40b7-84a6-bb2cc6c18384/46da51d9-2928-40b7-84a6-bb2cc6c183841.gif)
外文翻译英文文献使用两个DropDownList过滤的主从报表
Master/DetailFilteringWithTwoDropDownLists
Introduction
Intheprevioustutorialweexaminedhowtodisplayasimplemaster/detailsreportusingasingleDropDownListpopulatedwiththecategoriesandaGridViewshowingthoseproductsthatbelongtotheselectedcategory.Thisreportpatternworkswellwhendisplayingrecordsthathaveaone-to-manyrelationshipandcaneasilybeextendedtoworkforscenariosthatincludemultipleone-to-manyrelationships.Forexample,anorderentrysystemwouldhavetablesthatcorrespondtocustomers,orders,andorderlineitems.Agivencustomermayhavemultipleorderswitheachorderconsistingofmultipleitems.SuchdatacanbepresentedtotheuserwithtwoDropDownListsandaGridView.ThefirstDropDownListwouldhavealistitemforeachcustomerinthedatabasewiththesecondone'scontentsbeingtheordersplacedbytheselectedcustomer.AGridViewwouldlistthelineitemsfromtheselectedorder.
WhiletheNorthwinddatabaseincludethecanonicalcustomer/order/orderdetailsinformationinitsCustomers,Orders,andOrderDetailstables,thesetablesaren'tcapturedinourarchitecture.Nonetheless,wecanstillillustrateusingtwodependentDropDownLists.ThefirstDropDownListwilllistthecategoriesandthesecondtheproductsbelongingtotheselectedcategory.ADetailsViewwillthenlistthedetailsoftheselectedproduct.
Step1:
CreatingandPopulatingtheCategoriesDropDownList
OurfirstgoalistoaddtheDropDownListthatliststhecategories.Thesestepswereexaminedindetailintheprecedingtutorial,butaresummarizedhereforcompleteness.
OpentheMasterDetailsDetails.aspxpageintheFilteringfolder,addaDropDownListtothepage,setitsIDpropertytoCategories,andthenclicktheConfigureDataSourcelinkinitssmarttag.FromtheDataSourceConfigurationWizardchoosetoaddanewdatasource.
Figure1:
AddaNewDataSourcefortheDropDownList(Clicktoviewfull-sizeimage)
Thenewdatasourceshould,naturally,beanObjectDataSource.NamethisnewObjectDataSourceCategoriesDataSourceandhaveitinvoketheCategoriesBLLobject'sGetCategories()method.
Figure2:
ChoosetoUsetheCategoriesBLLClass(Clicktoviewfull-sizeimage)
Figure3:
ConfiguretheObjectDataSourcetoUsetheGetCategories()Method(Clicktoviewfull-sizeimage)
AfterconfiguringtheObjectDataSourcewestillneedtospecifywhichdatasourcefieldshouldbedisplayedintheCategoriesDropDownListandwhichoneshouldbeconfiguredasthevalueforthelistitem.SettheCategoryNamefieldasthedisplayandCategoryIDasthevalueforeachlistitem.
Figure4:
HavetheDropDownListDisplaytheCategoryNameFieldandUseCategoryIDastheValue(Clicktoviewfull-sizeimage)
AtthispointwehaveaDropDownListcontrol(Categories)that'spopulatedwiththerecordsfromtheCategoriestable.WhentheuserchoosesanewcategoryfromtheDropDownListwe'llwantapostbacktooccurinordertorefreshtheproductDropDownListthatwe'regoingtocreateinStep2.Therefore,checktheEnableAutoPostBackoptionfromthecategoriesDropDownList'ssmarttag.
Figure5:
EnableAutoPostBackfortheCategoriesDropDownList(Clicktoviewfull-sizeimage)
Step2:
DisplayingtheSelectedCategory'sProductsinaSecondDropDownList
WiththeCategoriesDropDownListcompleted,ournextstepistodisplayaDropDownListofproductsbelongingtotheselectedcategory.Toaccomplishthis,addanotherDropDownListtothepagenamedProductsByCategory.AswiththeCategoriesDropDownList,createanewObjectDataSourcefortheProductsByCategoryDropDownListnamedProductsByCategoryDataSource.
Figure6:
AddaNewDataSourcefortheProductsByCategoryDropDownList(Clicktoviewfull-sizeimage)
Figure7:
CreateaNewObjectDataSourceNamedProductsByCategoryDataSource(Clicktoviewfull-sizeimage)
SincetheProductsByCategoryDropDownListneedstodisplayjustthoseproductsbelongingtotheselectedcategory,havetheObjectDataSourceinvoketheGetProductsByCategoryID(categoryID)methodfromtheProductsBLLobject.
Figure8:
ChoosetoUsetheProductsBLLClass(Clicktoviewfull-sizeimage)
Figure9:
ConfiguretheObjectDataSourcetoUsetheGetProductsByCategoryID(categoryID)Method(Clicktoviewfull-sizeimage)
InthefinalstepofthewizardweneedtospecifythevalueofthecategoryIDparameter.AssignthisparametertotheselecteditemfromtheCategoriesDropDownList.
Figure10:
PullthecategoryIDParameterValuefromtheCategoriesDropDownList(Clicktoviewfull-sizeimage)
WiththeObjectDataSourceconfigured,allthatremainsistospecifywhatdatasourcefieldsareusedforthedisplayandvalueoftheDropDownList'sitems.DisplaytheProductNamefieldandusetheProductIDfieldasthevalue.
Figure11:
SpecifytheDataSourceFieldsUsedforth