DropDownList控件
1、DropDownList控件
<asp:DropDownList runat="server" ID="DropDownList1" AutoPostBack="true" OnSelectedIndexChanged="DropDownList_SelectedIndexChanged"></asp:DropDownList>
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ArrayList color = new ArrayList();
color.Add("Red");
color.Add("Green");
color.Add("Blue");
color.Add("LightGray");
DropDownList1.DataSource = color;
DropDownList1.DataBind();
}
}
protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
{
string color = this.DropDownList1.SelectedItem.Value;
switch (color)
{
case "Red":
this.DropDownList1.BackColor = System.Drawing.Color.Red;
break;
case "Green":
this.DropDownList1.BackColor = System.Drawing.Color.Green;
break;
case "Blue":
this.DropDownList1.BackColor = System.Drawing.Color.Blue;
break;
case "LightGray":
this.DropDownList1.BackColor = System.Drawing.Color.LightGray;
break;
default:
this.DropDownList1.BackColor = System.Drawing.Color.White;
break;
}
}
}
(1)获取DropDownList控件选项的索引号和标题
int Index = DropDownList1.SelectedIndex;//获取选项的索引号
int Index = DropDownList1.SelectedItem;//获取选项的标题
(2)向 DropDownList控件的下拉列表框中添加列表项
DropDownList1.Items.Add(new ListItem("ASP.NET","0"));
DropDownList1.Items.Add(new ListItem("VB.NET","1"));
DropDownList1.Items.Add(new ListItem("C#.NET","2"));
DropDownList1.Items.Add(new ListItem("VB","3"));
(3)删除选项的DropDownList控件的列表项
ListItem Item = DropDownList1.SelectedItem;
DropDownList1.Items.Remove(Item);
(4)清除所有DropDownList控件的列表项
DropDownList1.Items.Clear();
(5)获取DropDownList控件包含的列表项数
int count = DropDownList1.Items.Count;
DropDownList控件的更多相关文章
- DropDownList 控件不能触发SelectedIndexChanged 事件
相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...
- 三级联动---DropDownList控件
AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...
- c#中DropDownList控件绑定枚举数据
c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...
- DropDownList 控件
今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...
- DropDownList控件学习
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 客户端用JavaScript填充DropDownList控件 服务器端读不到值
填充没有任何问题,但是在服务器端却取不出来下拉表中的内容.页面代码如下. <form id="form1" runat="server"> < ...
- DropDownList 控件的SelectedIndexChanged事件触发不了
先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...
- 在FooterTemplate内显示DropDownList控件
如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...
- 《ASP.NET1200例》嵌套在DataLisT控件中的其他服务器控件---DropDownList控件的数据绑定
aspx <script type="text/javascript"> function CheckAll(Obj) { var AllObj = document. ...
随机推荐
- PostgreSQL-pg_dump,pg_restore
逻辑备份和psql一样,pg_dump.pg_restore有基本的和数据库连接的参数 -h 目标地址(对应环境变量$PGHOST) -p 连接端口(对应环境变量$PGPORT) -U 连接使用的用户 ...
- Linux 多线程可重入函数
Reentrant和Thread-safe 在单线程程序中,整个程序都是顺序执行的,一个函数在同一时刻只能被一个函数调用,但在多线程中,由于并发性,一个函数可能同时被多个函数调用,此时这个函数就成了临 ...
- Nova Suspend/Rescue 操作详解 - 每天5分钟玩转 OpenStack(35)
本节我们讨论 Suspend/Resume 和 Rescue/Unrescue 这两组操作. Suspend/Resume 有时需要长时间暂停 instance,可以通过 Suspend 操作将 in ...
- 算法: 斐波那契数列C/C++实现
斐波那契数列: 1,1,2,3,5,8,13,21,34,.... //求斐波那契数列第n项的值 //1,1,2,3,5,8,13,21,34... //1.递归: //缺点:当n过大时,递归 ...
- openstack命令备忘录
原文http://my.oschina.net/u/138210/blog/142661 查看rabbitmq 队列 rabbitmqctl list_queues 查看keystone的用户 key ...
- 安卓SeekBar
public class Speak extends Fragment implements OnSeekBarChangeListener { private SeekBar bar1; priva ...
- vim 命令详解
vi: Visual Interface 可视化接口vim: VI iMproved VI增强版 全屏编辑器,模式化编辑器 vim模式: 编辑模式(命令模式) 输入模式 末行模式 模式转换: 编辑-- ...
- Core 开发-Logging 使用NLog
ASP.NET Core 开发-Logging 使用NLog 写日志文件 ASP.NET Core 开发-Logging 使用NLog 写日志文件. NLog 可以适用于 .NET Core 和 ...
- c++适配器
容器适配器是是标准库中通用的概念,包括容器适配器.迭代器适配器和函数适配器,本质上,适配器是使一种事物的行为类似于另一种事物的的行为的一种机制,容器适配器使一种已经存在的容器类型采用另一种不同的抽象类 ...
- iOS widget开发
链接: iOS Widget开发 iOS开发之构建Widget iOS开发Widget iOS开发-widget基础 ios8新特性widget开发 ios 10 开发-widget实现 Widget ...