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 ...
随机推荐
- Property 'submit' of object #<HTMLFormElement> is not a function
<form action="" type="get" id="form"> <input type="butto ...
- chrome 49 版本bug: flex父元素设置flex:1 , 子元素用height:100%无法充满父元素
1 <div class="container"> <div class="item"> <div class="ite ...
- HDU4607 Park Visit
肯定会想到树的直径: 如果直径够长,就在直径(1+8)上面找路径,ans=k. 如果不够长,肯定会在有点分叉点(如3,4,5)回溯,然后我们把路径拉直,把其中一条的作为主线(有机化学,ORZ),主线是 ...
- java面试题9
1.选择题 public class Test01 { public static void changeStr(String str) { str = "welcome"; } ...
- WPF 的 ElementName 在 ContextMenu 中无法绑定成功?试试使用 x:Reference!
在 Binding 中使用 ElementName 司空见惯,没见它出过什么事儿.不过当你预见 ContextMenu,或者类似 Grid.Row / Grid.Column 这样的属性中设置的时候, ...
- ambassador 学习三 限速处理
与认证类似ambassador 也是委托给三方的其他服务进行限速处理 基本的环境安装可以参考相关文档,主要还是qotm 服务 官方参考实现的简单限速服务 --- apiVersion: v1 kind ...
- 五、jdk工具之jmap(java memory map)、 mat之四--结合mat对内存泄露的分析、jhat之二--结合jmap生成的dump结果在浏览器上展示
目录 一.jdk工具之jps(JVM Process Status Tools)命令使用 二.jdk命令之javah命令(C Header and Stub File Generator) 三.jdk ...
- Bootstrap-Plugin:折叠(Collapse)插件
ylbtech-Bootstrap-Plugin:折叠(Collapse)插件 1.返回顶部 1. Bootstrap 折叠(Collapse)插件 折叠(Collapse)插件可以很容易地让页面区域 ...
- Python链表与反链表
# -*- coding:utf8 -*- #/usr/bin/env python class Node(object): def __init__(self, data, pnext = None ...
- 图搜索——使用DFS和BFS耗时比较
图测试数据生成代码: #include<bits/stdc++.h> using namespace std; int random(int mod) { return rand() % ...