ASP.NET DropDownList的创建与填充

开发 后端
本文概括介绍了如何创建asp.net DropDownList并使用类别数据对其进行填充。

我们的***个目标是添加一个能够列出类别的DropDownList. 打开Filtering文件夹中的MasterDetailsDetails.aspx, 在页面上添加一个DropDownList, 设置它的ID为Categories,然后单击智能标记上的 Configure Data Source链接. 在数据源配置向导中选择新增一个数据源.

为DropDownList增加一个新的数据源 

ASP.NET DropDownList: 为DropDownList增加一个新的数据源

当然, 新的数据源应该是ObjectDataSource. 把新的ObjectDataSource命名为CategoriesDataSource并且让他调用CategoriesBLL对象的GetCategories()方法

选择使用CategoriesBLL类 

ASP.NET DropDownList: 选择使用CategoriesBLL类

配置ObjectDataSource使用GetCategories()方法 

ASP.NET DropDownList: 配置ObjectDataSource使用GetCategories()方法

配置完ObjectDataSource后还需要指定要在DropDownList中显示的数据字段,以及作为数据项的值(value for the list item)的数据字段.我们指定CategoryName为要显示的列,指定CategoryID为数据项的值字段

指定DropDownList 显示CategoryName列并且使用CategoryID列作为数据项的值 

ASP.NET DropDownList: 指定DropDownList 显示CategoryName列并且使用CategoryID列作为数据项的值

这时,我们就有了一个使用Categories表中的记录来填充的DropDownList控件. 当用户在DropDownList中选择一个新的类别时, 我们需要一次回发,这样可以刷新在第二步中我们要创建的产品DropDownList控件. 所以, categoriesDropDownList的智能标记上选中AutoPostBack选项.

选中Categories DropDownList 的AutoPostBack  

ASP.NET DropDownList: 选中Categories DropDownList 的AutoPostBack

【编辑推荐】

  1. ASP.NET 2.0数据教程:给站点添加aspx页面
  2. ASP.NET 2.0数据教程:创建母版页
  3. ASP.NET跨页面传值的技巧
  4. ASP.NET 2.0数据教程:给DAL添加定制编码
  5. ASP.NET 2.0数据教程:完成数据访问层

 

责任编辑:book05 来源: 博客堂
相关推荐

2009-07-27 09:45:14

ASP.NET Dro

2009-10-29 09:15:32

ASP.NET MVCDropDownLis

2009-07-31 17:34:40

ASP.NET工作流

2009-07-29 13:57:53

创建SlideShowASP.NET

2009-07-23 14:21:55

ASP.NET页面

2009-07-29 17:29:46

ASP与ASP.NET

2009-07-24 15:47:35

ASP.NET与ASP

2009-08-04 13:38:36

ASP.NET用户控件

2009-07-23 15:18:30

创建XML Web服务ASP.NET

2009-12-02 09:07:45

ASP.NET 4.0

2009-07-22 17:45:35

ASP.NET教程

2009-07-28 17:17:19

ASP.NET概述

2009-08-03 14:22:33

什么是ASP.NET

2009-07-28 14:10:14

2009-07-23 14:25:03

ASP.NET 2.0

2009-07-27 12:22:03

ASP.NET和ASPASP.NET入门教程

2009-07-29 10:56:54

ASP.NET构架与安

2009-07-29 09:38:06

Web开发ASP.NET

2010-07-28 14:11:49

Flexasp.net

2009-07-21 15:50:47

ASP.NET控件JavaScript
点赞
收藏

51CTO技术栈公众号