注意:
.如果用事件的话就要把控件的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的更多相关文章

  1. datagrid加下拉列表dropdownlist

    datagrid中代码: <asp:datagrid id="dgList" runat="server" ItemStyle-HorizontalAli ...

  2. js响应HTML客户端下拉列表的修改事件

    这个案例对经常写前端程序的人来讲应该比较简单,不过像我这种习惯于后台开发,对前端不熟悉的人来说,还是有参考意义的. 在asp.net里面,经常需要响应下拉列表DropDownList的Selected ...

  3. C#-WebForm-复合控件

    学习顺序:1.如何绑定数据 2.如何设置绑定项 3.如何取出数据 1.RadioButton - 单选按钮 RadioButtonList - 单选按钮组 控件中的ID生成了相同名字的 ID.Name ...

  4. ASP.NET MVC 3 入门级常用设置、技巧和报错

    1.ASP.NET MVC 3 如何去除默认验证 这个默认验证是在web.config配置文件中设置的    <add key="ClientValidationEnabled&quo ...

  5. Datalist增删改查——联系人管理

    关于Datalist,其实和Repeater差不多,都是存放数据的控件,相比较下,Datalist和Repeater虽然都是用的模板,但是Datalist比之多了Edit模板,也就是编辑栏的模板,事件 ...

  6. Gs_Class.Gs_DataFunction数据操作类库20160225

    using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security ...

  7. webform(复合控件)

    一.组合单选 RadioButtonList 单选按钮与简单控件不同,可理解为在集合中放置多对象 例: <asp:RadioButtonList ID="RadioButtonList ...

  8. ASP.NET MVC 3 常用

    http://blog.csdn.net/churujianghu/article/details/7297358 1.ASP.NET MVC 3 如何去除默认验证 这个默认验证是在web.confi ...

  9. kendo ui - DropDownList 下拉列表系列

    kendo-ui 官网:https://www.telerik.com/documentation 初始化 grid: 引入文件: <link rel="stylesheet" ...

随机推荐

  1. Setup Factory Error3014

    在用Setup Factory打包软件的时候出现Error3014 一般都是由于软件冲突引起的 我的问题是由于杀毒软件 ,在打包的时候关闭杀毒软件 就能成功打包了.

  2. 判断json数据是否为空

    json数据是没有length这个属性的 ,所以不能直接用.length()方法 我们可以先遍历,然后根据遍历次数求长度 1.在IE上这样遍历json:(js代码) var jsonLength = ...

  3. Windows下配置OpenGL环境

    这里编译工具为VS2012. 首先OpenGL的官网如下链接(英文) http://www.opengl.org http://www.opengl.org/resources/libraries/g ...

  4. (37) 在命令行调用API

    l 前言 有时为了更好地调整和改动数据会和到cli ,这会给我们带来更高的效率,基于官网的文档很是简单,这里就带大家一起运用 cli l 搭建 在项目下面有文件odoo.py 这个文件 ,对就是用这个 ...

  5. Construct Binary Tree from Preorder and Inorder Traversal [LeetCode]

    Given preorder and inorder traversal of a tree, construct the binary tree. Note:You may assume that ...

  6. Struts2 报 Result 错误

    写的时候犯了个低级错误  struts.xml中 配置result 的时候 没有配置type

  7. 2015 "BestCoder Cup" Champion

    这场比赛我没有参加,不过就算参加了也估计是被完虐.于是看着题解把大部分题目都搞了一遍. T1:Movie(hdu 5214) 题目大意: 给出N个区间,问能否选出3个互不相交的区间. N<=10 ...

  8. echart------属性详细介绍

    theme = { // 全图默认背景 // backgroundColor: 'rgba(0,0,0,0)', // 默认色板 color: ['#ff7f50','#87cefa','#da70d ...

  9. 替换Notes,K2 BPM为vivo打造新平台

    vivo是步步高旗下的分品牌,专注于智能手机领域,隶属于广东步步高工业电子有限公司.vivo追求乐趣.充满活力.年轻时尚的群体一起打造拥有卓越外观.专业级音质.极致影像.愉悦体验的智能产品,并将敢于追 ...

  10. 启动本地Oracle

    net start OracleOraDb10g_home1TNSListenernet start OracleServiceORCL第一个是监听服务第二个是数据库服务