DropDownList控件的使用方法
1. 使用代码添加数据
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList> //1.1使用代码添加数据
ListItem item = new ListItem(".net","");
this.DropDownList1.Items.Add(item);
item = new ListItem("java", "");
this.DropDownList1.Items.Add(item);
item = new ListItem("php", "");
this.DropDownList1.Items.Add(item);
item = new ListItem("选择全部", "");
this.DropDownList1.Items.Insert(, item);//在第一个索引处添加‘选择全部’选项
2. 使用代码绑定数据源
<asp:DropDownList ID="DropDownList2" runat="server">
</asp:DropDownList> //2.1使用代码绑定数据源
CategoriesManager manager = new CategoriesManager();
this.DropDownList2.DataSource=manager.GetDataTable();
this.DropDownList2.DataTextField = "name";
this.DropDownList2.DataValueField = "id";
this.DropDownList2.DataBind();
this.DropDownList2.Items.Insert(,new ListItem("选择全部", ""));
3. 使用数据绑定控件绑定数据源
<asp:DropDownList ID="DropDownList3" runat="server"
DataSourceID="SqlDataSource1" DataTextField="Name" DataValueField="Id">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:BookShopConnectionString %>"
SelectCommand="SELECT [Id], [Name] FROM [Categories]"></asp:SqlDataSource>
DropDownList控件的使用方法的更多相关文章
- Dropdownlist控件属性 OnSelectedIndexChanged方法不触发
<asp:DropDownList ID="ddlWJLX" runat="server" OnSelectedIndexChanged="dd ...
- 三级联动---DropDownList控件
AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为fl ...
- Jquery获得控件值的方法
一 Jquery获得服务器控件值的方法 由于ASP.NET网页运行后,服务器控件会随机生成客户端id,jquery获取时候不太好操作,google了下,总结有以下3种方法: 服务器控件代码:<a ...
- DropDownList 控件
今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...
- DropDownList 控件的SelectedIndexChanged事件触发不了
先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...
- 在FooterTemplate内显示DropDownList控件
如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...
- monkeyrunner之坐标或控件ID获取方法(六)
Monkeyrunner的环境已经搭建完成,现在对Monkeyrunner做一个简介. Monkeyrunner工具提供了一套API让用户/测试人员来调用,调用这些api可以控制一个Android设备 ...
- DropDownList控件
1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...
- DropDownList 控件不能触发SelectedIndexChanged 事件
相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...
随机推荐
- 一起玩转mysql
mysql安装 一起玩转mysql linux命令
- openssl RSA证书签发命令
一.生成根证书 1. 创建根证书私钥 openssl genrsa -out ca.key 2048 2. 创建根证书申请文件 openssl req -new -key ca.key -out ca ...
- AI人工智能专业词汇集
作为最早关注人工智能技术的媒体,机器之心在编译国外技术博客.论文.专家观点等内容上已经积累了超过两年多的经验.期间,从无到有,机器之心的编译团队一直在积累专业词汇.虽然有很多的文章因为专业性我们没能尽 ...
- threejs 通过bufferGeometry处理每一个点的位置和颜色
let positions = new Float32Array(points.length * 3); let colors = new Float32Array(points.length * 3 ...
- JavaWeb入门环境搭建
一.安装配置Tomcat 1.下载 2.配置环境变量 配置JAVA_HOME环境变量,路径为JDK的根目录 3.测试Tomcat 打开浏览器,在地址栏输入http://localhost:8080可以 ...
- tomcat自启动脚本
1.#cd /etc/rc.d/init.d2.#vi tomcat3.把下面的代码保存为tomcat文件,并让它成为可执行文件 chmod 755 tomcat. #!/bin/sh # # /et ...
- windows 如何查看端口占用进程ID 进程名称 强制结束进程
1.查看指定端口的占用情况C:\>netstat -aon|findstr "9050" 协议 本地地址 外部地址 ...
- 【nodeJS】webstorm中设置nodej智能提示
- PDB文件:每个开发人员都必须知道的 PDB Files
PDB文件:每个开发人员都必须知道的 PDB Files: What Every Developer Must Knowhttp://www.wintellect.com/CS/blogs/jro ...
- gradle windows上面安装配置
本文转载自: http://blog.csdn.net/u011546806/article/details/44806513 前提条件 安装jvm,并配置好了java环境变量 安装步骤 1.下载gr ...