All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
php+mysq 修改用户密码(用password加密)_[PHP教程]
用XMLHTTP对象抓取网页源代码,拆分数据写入数据库_[XML教程]
C#教程:COM+的概念
ASP.NET2.0,保存密码框的小技巧_[Asp.Net教程]
C#中显示XML文件使用实例
Visual C++ 6.0教程:c++数据类型之枚举
ASP.NET,2.0实现防止同一用户同时登陆_.net资料_编程技术
Access升迁SQL,Server_[SQL,Server教程]
XML,WebService完全实例详细解析_.net资料_编程技术
如何用.NET,Array类的Sort方法分类数值_.net资料_编程技术
Reading number is top 10 pictures
From China fortress sora aoi5
NeedWallpaper1
Sexy women in 2013--2
壮丽的云彩1
Green sweet joey wong young old photos exposure
The real super beauty4
这才叫绝色美女2
Angie Chiu vijara myth2
Fierce! China's special forces training the devil1
开始让人感动,后来......
Download software ranking
传奇私服架设教程
Ashlynn Video3
实战黑客不求人
Tram sex maniac 2 (H) rar bag7
The Bermuda triangle2
The cock of the Grosvenor LTD handsome
圣殿祭司的ASP.NET.2.0.开发详解-使用C#
Jinling thirteen stock
Unix video tutorial14
株洲本地在线棋牌游戏
qq published in(发表于) 2014/7/9 1:37:32 Edit(编辑)
asp.net2.0服务器控件之DropDownList控件

asp.net2.0服务器控件之DropDownList控件

asp.net2.0服务器控件之DropDownList控件

DropDownList控件

1.功能

DropDownList 控件与ListBox控件的使用方法类似,但DropDownList 控件只允许用户每次从列表中选择一项的下拉列表控件。DropDownList 控件只在框中显示选定项,同时还显示下拉按钮。当用户单击此按钮时,将显示项的列表。

2.属性

DropDownList控件常用属性及描述如表1所示。



表1 DropDownList控件常用属性及描述

DropDownList控件的属性大部分与ListBox控件相同,这里只介绍一下DataSource属性。

通过使用DataSource属性可以从数组或集合中获取列表项并将其添加到控件中。当编程人员希望从数组或集合中填充列表时,可以使用此属性。

语法:

object1.DataSource[= object2]

参数说明如下。

object1:对象表达式。

object2:对象表达式,其值是被添加到列表中的数据源对象。

例如,先创建一个数组arrList,代码如下:

ArrayList arrList = new ArrayList();

arrList.Add("red");

arrList.Add("blue");

arrList.Add("green");

arrList.Add("yellow");

使用DataSource属性将该数组附加到要填充的DropDownList控件中,代码如下:

this.ddlTest.DataSource = arrList;

3.方法

DropDownList控件最常用方法及描述如表2所示。



表2 DropDownList控件常用方法及描述

DataBind方法是在DropDownList控件使用DataSource属性附加了数据源后,将数据源绑定到被调用到DropDownList控件。

语法:

object. DataBind([bool]);

参数说明如下。

object:必需的,是一个对象表达式。

bool:可选的,是一个布尔表达式,它指定绑定数据源后是否引发DataBinding事件。

例如,将上例中的arrList数组绑定到DropDownList控件,代码如下:

this.ddlTest.DataBind();

4.事件

DropDownList控件常用事件及描述如表3所示。



表3 DropDownList控件常用事件及描述

DropDownList的事件与ListBox的事件十分相似,这里仅对SelectedIndexChanged事件作详细介绍。

与ListBox控件相同,当DropDownList控件的选项在向服务器发送过程中更改时,将引发 SelectedIndexChanged 事件。

* 示例

DropDownList控件SelectedIndexChanged事件的使用

本示例演示了在选取列表框中的某项时,将触发DropDownList控件SelectedIndex Changed事件,从而改变DropDownList控件的背景色。程序代码如下:

protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e)

{

string color=this.ddlTest .SelectedValue ;

if(color =="red")

this.ddlTest.BackColor=System .Drawing .Color.Red ;

if (color == "blue")

this.ddlTest.BackColor = System.Drawing.Color.Blue;

if (color == "green")

this.ddlTest.BackColor = System.Drawing.Color.Green ;

if (color == "yellow")

this.ddlTest.BackColor = System.Drawing.Color.Yellow;

}

运行结果如图1所示



图1 SelectedIndexChanged事件示例运行结果

完整程序代码如下:

★ ★★★★DropDownListTest.aspx代码文件完整程序代码★★★★★

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="DropDownListTest.aspx.cs" Inherits="DropDownListTest" %>







DropDownListTest











添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.