WebForm 三级联动
三级联动
数据库根据父级代号条件写查询 返回list<>集合
方法一:
创建三个下拉列表:
※AutoPostBack:否发生自动回传到服务器的操作。如果把该属性设置为 TRUE,则启用自动回传,否则为 FALSE。默认是 FALSE。
省:<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True"></asp:DropDownList>
市:<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True"></asp:DropDownList>
区:<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True"></asp:DropDownList>
CS:
※SelectedIndexChanged事件:当列表控件的选定项在信息发往服务器之间变化时发生
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
Bind(new ChinaStatesDA().Select(""), DropDownList1);
Bind(new ChinaStatesDA().Select(DropDownList1.SelectedValue), DropDownList2);
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
}
DropDownList1.SelectedIndexChanged += DropDownList1_SelectedIndexChanged;
DropDownList2.SelectedIndexChanged += DropDownList2_SelectedIndexChanged;
} void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
} void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Bind(new ChinaStatesDA().Select(DropDownList1.SelectedValue), DropDownList2);
Bind(new ChinaStatesDA().Select(DropDownList2.SelectedValue), DropDownList3);
}
//绑定方法
public void Bind(List<ChinaStates> list, DropDownList dw)
{
dw.DataSource = list;
dw.DataTextField = "AreaName";
dw.DataValueField = "AreaCode";
dw.DataBind();
}
方法二:
创建三个下拉列表框:
省:<asp:DropDownList ID="DropDownListsheng" runat="server" OnSelectedIndexChanged="DropDownListsheng_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
市:<asp:DropDownList ID="DropDownListshi" runat="server" OnSelectedIndexChanged="DropDownListshi_SelectedIndexChanged" AutoPostBack="True"></asp:DropDownList>
区:<asp:DropDownList ID="DropDownListqu" runat="server" AutoPostBack="True"></asp:DropDownList>
CS:
※DropDownList.Items.Clear(); 每调用一次填充方法就需要请空一下,否则数据会追加
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
sheng();
shi();
qu();
}
}
public void sheng()//填充省
{
List<ChinaStates> listsheng = new ChinaStatesDA().Select("");
foreach (ChinaStates cssheng in listsheng)
{
ListItem lisheng = new ListItem(cssheng.AreaName, cssheng.AreaCode);
DropDownListsheng.Items.Add(lisheng);
}
}
public void shi()//填充市
{ List<ChinaStates> listshi = new ChinaStatesDA().Select(DropDownListsheng.SelectedValue);
foreach (ChinaStates csshi in listshi)
{
ListItem lishi = new ListItem(csshi.AreaName, csshi.AreaCode);
DropDownListshi.Items.Add(lishi);
}
}
public void qu()//填充区
{ List<ChinaStates> listqu = new ChinaStatesDA().Select(DropDownListshi.SelectedValue);
foreach (ChinaStates csqu in listqu)
{
ListItem liqu = new ListItem(csqu.AreaName, csqu.AreaCode);
DropDownListqu.Items.Add(liqu);
} }
protected void DropDownListsheng_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListshi.Items.Clear();
DropDownListqu.Items.Clear();
shi();
qu();
}
protected void DropDownListshi_SelectedIndexChanged(object sender, EventArgs e)
{
DropDownListqu.Items.Clear();
qu();
}
WebForm 三级联动的更多相关文章
- Webform 三级联动例子
首先分别做三个下拉列表 <body> <form id="form1" runat="server"> <asp:DropDown ...
- Webform——中国省市三级联动以及IsPostBack
首先要明白Webform的运行顺序,当开始启动时候,首先执行的是Page_Load事件, 当点击任意按钮后,每次点击都要先执行一遍Page_Load(在这里Page_Load里面的事件是给数据控件加载 ...
- webform的三级联动
webform的三级联动 与winform一样,只不过需把DropDownList的AutoPostBack属性改为True. *简单日期的编写方法:用是三个DropDownList分别代表年月日,用 ...
- webForm(三)——三级联动
三级联动 首先附图一张,初步认识一下什么是三级联动: 注:选第一个后面两个变,选第二个,最后一个改变. 其次,做三级联动需要注意的方面:①DropD ...
- 注册页面的验证 WEB的三级联动
1.js中window.onload = function () {};表示当页面都加载完了之后才走里面的内容. 2.当函数中遇到return时,会跳出函数,return后面的内容不再继续进行,就是后 ...
- js封装的三级联动菜单(使用时只需要一行js代码)
前言 在实际的项目开发中,我们经常需要三级联动,比如省市区的选择,商品的三级分类的选择等等. 而网上却找不到一个代码完整.功能强大.使用简单的三级联动菜单,大都只是简单的讲了一下实现思路. 下面就给大 ...
- 利用select实现年月日三级联动的日期选择效果
× 目录 [1]演示 [2]规划 [3]结构生成[4]算法处理 前面的话 关于select控件,可能年月日三级联动的日期选择效果是最常见的应用了.本文是选择框脚本的实践,下面将对日期选择效果进行详细介 ...
- jQuery省市区三级联动插件
体验效果:http://hovertree.com/texiao/bootstrap/4/支持PC和手机移动端. 手机扫描二维码体验效果: 代码如下: <!DOCTYPE html> &l ...
- jQuery - 全国省市县三级联动
最近有空用jquery做了一个全国省市县的三级联动,在以后或许可以用的到 ,遗憾的是我还没用封装,等有空看能不能封装成一个插件 废话不多说,贴上代码: <!doctype html> &l ...
随机推荐
- (四)Jquery Mobile表单
Jquery Mobile表单与列表 一.JM表单 1.表单 普通html表单 效果: 2.只能输入数字的表单 效果: ...
- Attribute name invalid for tag form according to TLD异常解决办法_gaigai_百度空间
body{ font-family: "Microsoft YaHei UI","Microsoft YaHei",SimSun,"Segoe UI& ...
- 变量-数据类型-对象-如何编写python脚本
标识符的命名规则变量是标识符的例子. 标识符 是用来标识 某样东西 的名字.在命名标识符的时候,你要遵循这些规则:标识符的第一个字符必须是字母表中的字母(大写或小写)或者一个下划线(‘ _ ’).标识 ...
- Sping--集合注入
UserDAOImpl.java: package com.bjsxt.dao.impl; import java.util.List; import java.util.Map; import ja ...
- MySQL 启动、关闭、选择数据库等命令
一.MySQL服务的启动和停止 1.net 命令来启动或停止mysql服务 net stop mysql(mysql是指你真正装的服务,如果装的是 mysql5,必须写成 net stop mysql ...
- Leetcode题1
Given an array of integers, find two numbers such that they add up to a specific target number. The ...
- OpenGL ES
前言 OpenGL ES是Khronos Group创建的一系列API中的一种(官方组织是:http://www.khronos.org/).在桌面计算机上有两套标准的 3DAPI:Direct3D和 ...
- mysqladmin: connect to server at 'localhost' failed error: 'Access denied for user 'root'@'localhost' (using password: YES)'
就当作自己忘记Mysql密码把,忘记密码的解决方法 一.mysql登录错误mysqladmin: connect to server at 'localhost' failederror: 'Acce ...
- 背景图片等比缩放的写法background-size简写法
1.背景图片或图标也可像img一样给其宽高就能指定其缩放大小了. 比如一个实际宽高36*28的图标,要缩小一半引用进来的写法就是: background:rgba(0, 0, 0, 0) url(&q ...
- PHP mysqli连接MySQL数据库
1. 开启PHP的API支持 (1)首先修改您的php.ini的配置文件.查找下面的语句:;extension=php_mysqli.dll将其修改为:extension=php_mysqli.dll ...