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. ...
随机推荐
- JS/JQuery针对不同类型元素的操作(radio、select、checkbox)
一.select下拉框 I:javascript方法 1:获取选中的值 F1: var myselect=document.getElementById("test");或者 ...
- WPF 自定义雷达图
自定义雷达图表如下: Git下载地址:https://github.com/Kybs0/RadarChartControl 1.创建UserControl,名为“RadarChartControl” ...
- C++使用binder实例
Android系统最常见也是初学者最难搞明白的就是Binder了,很多很多的Service就是通过Binder机制来和客户端通讯交互的.所以搞明白Binder的话,在很大程度上就能理解程序运行的流程. ...
- MongoDB官方C#驱动中查询条件Query用法
Query.All("name", "a", "b");//通过多个元素来匹配数组 Query.And(Query.EQ("nam ...
- Jekyll + Github 搭建属于你的静态博客
1. 搭建Jekyll环境 linux下jekyll的安装非常简单,这里主要讲一下windows下的jekyll的安装过程 这是一台刚刚装完系统的win10系统,它什么都没有,让我们从零开始. 1.1 ...
- SpringMVC 返回json
1.导入jackson的jar包 2.在方法体上加上@ResponseBody /** * 得到ProType的typeId,typeName列表 * 返回json * */ @RequestMapp ...
- 第1章 重构,第一个案例(2):分解并重组statement函数
2. 分解并重组statement (1)提炼switch语句到独立函数(amountFor)和注意事项. ①先找出函数内的局部变量和参数:each和thisAmount,前者在switch语句内未被 ...
- Ajax与JqueryUI和EasyUI错题总结
Ajax与JqueryUI和EasyUI错题总结 正确答案A,解析:此题考察的是JQuery UI下的menu插件的使用,menu提供ui-state-disabled class 方法禁用任何菜单项 ...
- jquery的css详解(一)
通过阅读源码可以发现css是jq的实例方法.而在内部调用jq的工具方法access来实现的,对该方法不了解的朋友请点击 -> jquery工具方法access详解 在access的回调中做了一个 ...
- codevs 2894 保留小数
时间限制: 1 s 空间限制: 128000 KB 题目等级 : 白银 Silver 题目描述 Description 给你一个实数,小数点后不超过50位,请你保留到小数点后n位(四舍五入!!!) 输 ...