20151214下拉列表:DropDownList
注意:
.如果用事件的话就要把控件的AutoPostBack设置成true
.防止网页刷新用一个判断 if (!IsPostBack)//判断是第一个开始还是取的返回值
{
} 下拉列表:DropDownList
.绑定数据:
//指定数据源
DropDownList1.DataSource = context.Nation;
DropDownList1.DataValueField = "Code";
DropDownList1.DataTextField = "Name";
//绑定数据源
DropDownList1.DataBind(); //新建一个集合,往dropdownlist里面添加集合
ListItem item = new ListItem();
item.Text = "中国";
item.Value = "";
DropDownList1.Items.Add(item); 也可以在dropdownlist上面选择数据源 .取选中项的值
DropDownList1.SelectedValue.ToString(); .设置哪一项选中
DropDownList1.SelectedIndex = ; //便利
foreach (ListItem item in DropDownList1.Items)
{
if (item.Value == "n002")
{
item.Selected = true;
}
} 三级联动
private DataClassesDataContext context = new DataClassesDataContext(); protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
FillSheng();
FillShi();
FillQu();
}
} public void FillSheng()
{
DropDownList1.DataSource = context.ChinaStates.Where(r => r.ParentAreaCode == "");
DropDownList1.DataValueField = "AreaCode";
DropDownList1.DataTextField = "AreaName";
DropDownList1.DataBind();
} public void FillShi()
{
string sheng = DropDownList1.SelectedValue.ToString(); DropDownList2.DataSource = context.ChinaStates.Where(r => r.ParentAreaCode == sheng);
DropDownList2.DataValueField = "AreaCode";
DropDownList2.DataTextField = "AreaName";
DropDownList2.DataBind();
} public void FillQu()
{
string shi = DropDownList2.SelectedValue.ToString(); DropDownList3.DataSource = context.ChinaStates.Where(r => r.ParentAreaCode == shi);
DropDownList3.DataValueField = "AreaCode";
DropDownList3.DataTextField = "AreaName";
DropDownList3.DataBind();
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
FillShi();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
FillQu();
}
20151214下拉列表:DropDownList的更多相关文章
- datagrid加下拉列表dropdownlist
datagrid中代码: <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAli ...
- js响应HTML客户端下拉列表的修改事件
这个案例对经常写前端程序的人来讲应该比较简单,不过像我这种习惯于后台开发,对前端不熟悉的人来说,还是有参考意义的. 在asp.net里面,经常需要响应下拉列表DropDownList的Selected ...
- C#-WebForm-复合控件
学习顺序:1.如何绑定数据 2.如何设置绑定项 3.如何取出数据 1.RadioButton - 单选按钮 RadioButtonList - 单选按钮组 控件中的ID生成了相同名字的 ID.Name ...
- ASP.NET MVC 3 入门级常用设置、技巧和报错
1.ASP.NET MVC 3 如何去除默认验证 这个默认验证是在web.config配置文件中设置的 <add key="ClientValidationEnabled&quo ...
- Datalist增删改查——联系人管理
关于Datalist,其实和Repeater差不多,都是存放数据的控件,相比较下,Datalist和Repeater虽然都是用的模板,但是Datalist比之多了Edit模板,也就是编辑栏的模板,事件 ...
- Gs_Class.Gs_DataFunction数据操作类库20160225
using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...
- webform(复合控件)
一.组合单选 RadioButtonList 单选按钮与简单控件不同,可理解为在集合中放置多对象 例: <asp:RadioButtonList ID="RadioButtonList ...
- ASP.NET MVC 3 常用
http://blog.csdn.net/churujianghu/article/details/7297358 1.ASP.NET MVC 3 如何去除默认验证 这个默认验证是在web.confi ...
- kendo ui - DropDownList 下拉列表系列
kendo-ui 官网:https://www.telerik.com/documentation 初始化 grid: 引入文件: <link rel="stylesheet" ...
随机推荐
- C语言语法之关键字
注:该内容整理自以下链接. http://www.cnblogs.com/yezhenhan/archive/2011/10/16/2214420.html 由ANSI标准定义的C语言关键字共32个: ...
- SQL Server去掉字段内的双引号
今天在客户处遇到一个问题,用powershell抓取出的数据插入SQL中后每个字段都会自动带双引号“”如下: 现在想将此双引号去掉,用下面语句即可: insert into #A select SUB ...
- spring+mongo
一.程序结构
- maven依赖非maven库中jar的两种方法
1.利用 maven-compiler-plugin <plugin> <groupId>org.apache.maven.plugins</groupId> &l ...
- Python爬虫:一些常用的爬虫技巧总结
爬虫在开发过程中也有很多复用的过程,这里总结一下,以后也能省些事情. 1.基本抓取网页 get方法 import urllib2 url = "http://www.baidu.com&qu ...
- PetShop的系统架构设计
<解剖PetShop>系列 一.PetShop的系统架构设计 http://www.cnblogs.com/wayfarer/archive/2007/03/23/375382.html ...
- ijg库的使用的几点注意
ijg库(http://www.ijg.org/)是用于处理jpeg解码和压缩的库,最新版本为2014发布的版本,可以在官网中下载jpegsr9a.zip 使用vs中个nmake 进行编译,对于这个版 ...
- mysql 删除重复数据保留一条
验证:mysql 5.6版本 方法一: delete a from table a left join( select (id) from table group by studentName,cla ...
- Java使用ZXing生成二维码条形码
一.下载Zxingjar包 本实例使用的是 zxing3.2.0的版本 下载地址 http://pan.baidu.com/s/1gdH7PzP 说明:本实例使用的3.2.0版本已经使用的java7 ...
- 不错的TOMCAT监控好工具probe
Tomcat版本:6.0.41 Probe版本:2.3.3 一,Tomcat没有默认用户账号,故首先需要添加Tomcat用户账号 修改$CATALINA_HOME/conf/tomcat-users. ...