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 ...
随机推荐
- Apache处理请求步骤及过程
Apache请求处理循环详解 : 1.Post-Read-Request阶段: 在正常请求处理流程中,这是模块可以插入钩子的第一个阶段.对于那些想很早进入处理请求的模块来说,这个阶段可以被利用. 2. ...
- url语法
URL的主要部分 URL通常被写成如下形式: <方案>:<方案描述部分> 一个URL包含了它使用的方案名称(<方案>), 其后紧跟一个冒号,然后是一个字符串 (&l ...
- android测试之——mokeyrunner上(二)
以下是本人原创,如若转载和使用请注明转载地址.本博客信息切勿用于商业,可以个人使用,若喜欢我的博客,请关注我,谢谢!博客地址 感谢您支持我的博客,我的动力是您的支持和关注!如若转载和使用请注明转载地址 ...
- $_SERVER参数的含义
$_SERVER是由服务器创建的,包含了头信息.参数.路径等信息,以下是一些键代表的含义: $_SERVER['PHP_SELF'] #当前正在执行脚本的文件名,与 document root相关.$ ...
- webform中 ajax调用后台方法(非webservice)
方法一:通过创建一个没有内容的窗体 后台: public partial class Ajax_ShoppingCart : System.Web.UI.Page { bookdbDataContex ...
- STM32F103 使用TIM3产生四路PWM
STM32F103 使用TIM3产生四路PWM 程序如下: /********************************************************************* ...
- 360路由器设置网段ip
路由器设置->高级设置->修改路由器地址
- Leetcode 176. Second Highest Salary
Write a SQL query to get the second highest salary from the Employee table. +----+--------+ | Id | S ...
- kmp算法理解与记录
字符串匹配的暴力解法 给定字符串s和p,寻找字符串p在字符串s中出现的位置,暴力解法如下所示: 如果当前字符匹配成功,++i;++j,继续匹配下一字符. 如果s[i]与s[j]匹配失败,令i-=(j- ...
- StackExchange.Redis 官方文档(二) Configuration
配置 有多种方式可以配置redis,StackExchange.Redis提供了一个丰富的配置模型,在执行Connect (or ConnectAsync) 时被调用: var conn = Conn ...