ASP.NET DropDownList使用范例
ASP.NET DropDownList類別顯示
我們的主/從報表將會在DropDownList中列出類別, 根據(jù)選擇的列表項在頁面上的GridView顯示相關(guān)的產(chǎn)品. 我們的第一任務, 就是要在DropDownList中顯示類別. 打開Filtering文件夾中的FilterByDropDownList.aspx, 從工具箱中將一個DorpDownList控件拖放在該頁上, 設(shè)置它的ID屬性為Categories. 然后, 單擊”DropDownList 任務”上的”選擇數(shù)據(jù)源”鏈接. “選擇數(shù)據(jù)源”向?qū)?
ASP.NET DropDownList:指定DropDownList控件的數(shù)據(jù)源
添加一個數(shù)據(jù)源控件并命名為CategoriesDataSource,該控件將會調(diào)用CategoriesBLL 類的 GetCategories().
ASP.NET DropDownList: 添加一個數(shù)據(jù)源控件并命名為CategoriesDataSource
ASP.NET DropDownList: 選擇使用CategoriesBLL 類
ASP.NET DropDownList: 配置數(shù)據(jù)源控件使用GetCategories() 方法
配置完ObjectDataSource后還需要指定要在DropDownList中顯示的數(shù)據(jù)字段,以及作為數(shù)據(jù)項的值(value for the list item)的數(shù)據(jù)字段.我們指定CategoryName為要顯示的列, 指定CategoryID為數(shù)據(jù)項的值字段
ASP.NET DropDownList: 指定CategoryName為要顯示的列, CategoryID作為數(shù)據(jù)項的值。
這時,我們就有了一個使用Categories表中的記錄來填充的DropDownList控件.圖6顯示了在瀏覽器中所看到的目前為止我們所做的工作.
ASP.NET DropDownList:DropDownList列出了當前的類別
【編輯推薦】
- ASP.NET 2.0數(shù)據(jù)教程:給站點添加aspx頁面
- ASP.NET 2.0數(shù)據(jù)教程:創(chuàng)建母版頁
- ASP.NET跨頁面?zhèn)髦档募记?/A>
- ASP.NET 2.0數(shù)據(jù)教程:給DAL添加定制編碼
- ASP.NET 2.0數(shù)據(jù)教程:完成數(shù)據(jù)訪問層