博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
三级联动
阅读量:4541 次
发布时间:2019-06-08

本文共 2902 字,大约阅读时间需要 9 分钟。

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %>
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;public partial class Default4 : System.Web.UI.Page{    DataClasses2DataContext context = new DataClasses2DataContext();//linQ方式获取数据库数据    List
lc = new List
();//初始化一个Chinastates类的泛型集合 protected void Page_Load(object sender, EventArgs e) { DropDownList1.SelectedIndexChanged += DropDownList1_SelectedIndexChanged;//委托方法便捷写法,如果需要查询该方法,把光标移动到要找的对象上,按F12自动跳转 DropDownList2.SelectedIndexChanged += DropDownList2_SelectedIndexChanged; lc = context.ChinaStates.ToList();//lc接受调取数据库里Chinastates转换为list集合的形式数据 if(IsPostBack==false)//只加载一遍 { //省数据 List
sheng = lc.Where(r => r.ParentAreaCode == "0001").ToList();//调取省的数据 DropDownList1.DataSource = sheng;//将DropDownList1的数据指向sheng DropDownList1.DataTextField = "AreaName";//DropDownList1的文本文件的名称为AreaName DropDownList1.DataValueField = "AreaCode";//DropDownList1的值得文件名称为AreaCode DropDownList1.DataBind();//DropDownList1绑定数据 //市数据 List
shi = lc.Where(r => r.ParentAreaCode == DropDownList1.SelectedItem.Value).ToList(); DropDownList2.DataSource = shi; DropDownList2.DataTextField = "AreaName"; DropDownList2.DataValueField = "AreaCode"; DropDownList2.DataBind(); //县数据 List
xian = lc.Where(r => r.ParentAreaCode == DropDownList2.SelectedItem.Value).ToList(); DropDownList3.DataSource = xian; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaCode"; DropDownList3.DataBind(); } } void DropDownList2_SelectedIndexChanged(object sender, EventArgs e) { //县数据 List
xian = lc.Where(r => r.ParentAreaCode == DropDownList2.SelectedItem.Value).ToList(); DropDownList3.DataSource = xian; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaCode"; DropDownList3.DataBind(); } void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { //市数据 List
shi = lc.Where(r => r.ParentAreaCode == DropDownList1.SelectedItem.Value).ToList(); DropDownList2.DataSource = shi; DropDownList2.DataTextField = "AreaName"; DropDownList2.DataValueField = "AreaCode"; DropDownList2.DataBind(); //县数据 List
xian = lc.Where(r => r.ParentAreaCode == DropDownList2.SelectedItem.Value).ToList(); DropDownList3.DataSource = xian; DropDownList3.DataTextField = "AreaName"; DropDownList3.DataValueField = "AreaCode"; DropDownList3.DataBind(); }}

转载于:https://www.cnblogs.com/fengsantianya/p/5680136.html

你可能感兴趣的文章
安装PHP以及搭建博客(一)
查看>>
关于WORD文档的读取乱码问题
查看>>
[问题记录.dotnet]取网卡信息报错"找不到"-WMI - Not found
查看>>
Codeforces Round #254 (Div. 2):B. DZY Loves Chemistry
查看>>
linux 安装虚拟机
查看>>
Thinkphp5笔记二:创建模块
查看>>
centos 安装mysql
查看>>
Redis 禁用FLUSHALL FLUSHDB KEYS 命令
查看>>
Matlab中imread函数使用报错“不应为MATLAB 表达式”分析
查看>>
MFC ADO数据库操作
查看>>
图像质量评价-NQM和WPSNR
查看>>
面试准备——相关知识
查看>>
每日一字:悟
查看>>
CentOS7.6安装稳定版Nginx
查看>>
LeetCode 1002. Find Common Characters (查找常用字符)
查看>>
建立隐藏管理员用户
查看>>
android设置图文提醒功能
查看>>
ajax跨域提交
查看>>
完成登录与注册页面的前端
查看>>
Mac下source tree 下的安装
查看>>