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. ...
随机推荐
- 安装免费的正版Windows10操作系统 - 初学者系列 - 学习者系列文章
Windows 10操作系统是目前Windows平台最新的操作系统,其相对于其它旧版的操作系统是一个比较成功的操作系统.微软直接使用10版本号,跳过了9版本号进行发布这款操作系统,说明windows ...
- tomcat 应用部署的几点注意
将应用部署到Tomcat根目录的目的是可以通过"http://[ip]:[port]"直接访问应用,而不是使用"http://[ip]:[port]/[appName]& ...
- TNS-12540: TNS:internal limit restriction exceeded
应用程序以及客户端工具(Toad.PL/SQL Developer等)出现突然连接不上数据库服务器的情况,监听日志listener.log里面出现了TSN-12518与TSN-12540错误,如下所示 ...
- Linux命令学习总结:reboot命令
命令简介: 该命令用来重启Linux系统.相当于Windows系统中的restart命令. 命令语法: /sbin/reboot [-n] [-w] [-d] [-f] [-i] 或 reboot [ ...
- [MySQL Reference Manual]14 InnoDB存储引擎
14 InnoDB存储引擎 14 InnoDB存储引擎 14.1 InnoDB说明 14.1.1 InnoDB作为默认存储引擎 14.1.1.1 存储引擎的趋势 14.1.1.2 InnoDB变成默认 ...
- Spring配置JNDI和通过JNDI获取DataSource
一.SpringJNDI数据源配置信息 <bean id="dataSource" class="org.springframework.jndi.JndiObje ...
- oracle in VS or效率
select * from test where status in ('01', '02', '03', '111'); select * from test where status = '01' ...
- Solr图形化界面banana:除Hue之外的选择
最近Hue+Solr 方案原型验证有了一些进展.正好也收到了Google的大数据专家Sam的来件询问进展,我答复如下: Sam, 你好. 已经把Kafka+flume+solr的实时索引搭建起来了, ...
- Yii2 使用a标签发送post请求
<?= Html::a('text', 'url', [ 'data' => [ 'method' => 'post', 'params' => [ 'params_key' ...
- 在Windows Server 2012 R2中搭建SQL Server 2012故障转移集群
需要说明的是我们搭建的SQL Server故障转移集群(SQL Server Failover Cluster)是可用性集群,而不是负载均衡集群,其目的是为了保证服务的连续性和可用性,而不是为了提高服 ...