DropDownList四级联动
前台代码:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="iframe_dropdown.aspx.cs" Inherits="Admin_iframe_dropdown" %> <!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server" />
<div style="float: left" >
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:DropDownList ID="DropDownList1" runat="server" Width="105px" AutoPostBack="true"
OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged" >
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="true" Width="105px"
OnSelectedIndexChanged="DropDownList2_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="true" Width="105px"
OnSelectedIndexChanged="DropDownList3_SelectedIndexChanged">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="true" Width="105px"
OnSelectedIndexChanged="DropDownList4_SelectedIndexChanged">
</asp:DropDownList>
</ContentTemplate>
</asp:UpdatePanel>
</div>
<div style="float: left" >
</div> </form>
</body>
</html>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Collections;
using System.Text; public partial class Admin_iframe_dropdown : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{ if (!IsPostBack)
{
Db1DataBind();
Db2DataBind();
Db3DataBind();
Db4DataBind();
}
} protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Db2DataBind();
Db3DataBind();
Db4DataBind();
}
protected void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
Db3DataBind();
Db4DataBind();
}
protected void DropDownList3_SelectedIndexChanged(object sender, EventArgs e)
{
Db4DataBind();
}
protected void DropDownList4_SelectedIndexChanged(object sender, EventArgs e)
{ } public void Db1DataBind()
{
string sqlStr = "select ModID,ModName,ParentID from Modules where ParentID=0000";
FillDropList(sqlStr, DropDownList1); }
public void Db2DataBind()
{
int PreID = Convert.ToInt32(DropDownList1.SelectedValue);
string sqlStr1 = "Select ModID,ModName,ParentID from Modules where ParentID='" + PreID.ToString() + "'";
FillDropList(sqlStr1, DropDownList2);
}
public void Db3DataBind()
{
int PreID = Convert.ToInt32(DropDownList2.SelectedValue);
string sqlStr2 = "Select ModID,ModName,ParentID from Modules where ParentID='" + PreID.ToString() + "'";
FillDropList(sqlStr2, DropDownList3);
}
public void Db4DataBind()
{
string PreID = Convert.ToString(DropDownList3.SelectedValue);
string sqlStr3 = "Select ModID,ModName,ParentID from Modules where ParentID='" + PreID.ToString() + "'";
FillDropList(sqlStr3, DropDownList4);
}
public void FillDropList(string SQLString, DropDownList drp)
{
SqlConnection connection = new SqlConnection("database=ZJExpress;server=(local);uid=sa;pwd=hellocheng");
SqlCommand cmd = new SqlCommand(SQLString, connection);
SqlDataAdapter sda = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
sda.Fill(ds, "DropList");
drp.DataSource = ds.Tables["DropList"].DefaultView;
drp.DataTextField = ds.Tables["DropList"].Columns[].ColumnName;
drp.DataValueField = ds.Tables["DropList"].Columns[].ColumnName;
drp.DataBind();
}
}
参考链接http://blog.csdn.net/wxd_860825/article/details/4563368
DropDownList四级联动的更多相关文章
- C# 使用winForm的TreeView显示中国城镇四级联动
直接上代码吧,这里 MySql.Data.MySqlClient;需要到mysql官网下载mysql-connector-net-6.9.8-noinstall.zip 访问密码 6073 usi ...
- jq完成省市区街道四级联动
之前看的省市区街道四级联动的插件,感觉和公司要求的有些不符合,就自己写了一个 因为要读取本地json文件,所以要跑下服务器 下载browser-sync 然后在项目目录下运行browser-sync ...
- discuz 自带的地区四级联动调用方法
首先,DZ提供了专门处理地区信息的函数,在source/function/function_profile.php(第14行)文件中:function profile_setting(){}那么,我们 ...
- .net DropDownList静态联动
1.前台 <span id="spnClient" style="margin-left: 30px; margin-top: 10px"> < ...
- 省市县 三级 四级联动Javascript JQ 插件PCASClass.js
想要使用这款组件,需要页面引入 PCASClass.js 核心文件,该文件在您的HTML文档<head>标签之内. <script type="text/javascrip ...
- js 四级联动
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head ...
- ASP .NET DropDownList多级联动事件
思路 假如有三级省.市.区,先加载出所有省选择省之后,加载出该省所有市选择市之后,加载出该市所有区重新选择省,则清空市和区重新选择市,则清空区想好数据结构,不同的数据结构做法不同 例子 数据结构 pu ...
- dropdownlist 二级联动
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { GradeBind(); } } //绑定 ...
- 地址四级联动的vue组件
一.效果图如下: 二.思路 主要在vue中结合 mint-ui组件的Picker和Popup方法,负责对json地址进行展示: 三.代码地址 四.说明 address4.json最好是在点击父组件的地 ...
随机推荐
- Linux内核中常见内存分配函数(二)
常用内存分配函数 __get_free_pages unsigned long __get_free_pages(gfp_t gfp_mask, unsigned int order) __get_f ...
- #include <boost/weak_ptr.hpp>
弱指针boost::weak_ptr的定义在boost/weak_ptr.hpp里.到目前为止介绍的各种智能指针都能在不同的场合下独立使用.相反,弱指针只有在配合共享指针一起使用时才有意义.因此弱指针 ...
- 手机端页面自适应:rem布局
rem布局非常简单,首页你只需在页面引入这段原生js代码就可以了 (function (doc, win) { var docEl = doc.documentElement, resizeEvt = ...
- docker相关配置
一.概述: 1.centos7下,默认firewalld为防火墙, systemctl status firewalld.service 2.关闭firewalld, systemctl stop f ...
- Silverlight学习(三)
最近对WCFRIA+MVVM+Prism有了初步的认识,能够简单的实现一些数据库的交互.这节主要讲的是Silverlight通过domainservice和ado.net实体数据模型与数据库的交互.本 ...
- C#文件读写操作
方法1:使用FileStream读写文件 using System;using System.Collections.Generic;using System.Text;using System.IO ...
- 数据库————Select 查询
--创建mydb数据库create database mydb go --使用数据库use mydb go --水果表 create table Fruit ( Ids varchar() prima ...
- Java 反射机制浅析
Java反射机制是在运行状态中,对于任意一个类,都能够知道这个类的所有属性和方法:对于任意一个对象,都能够调用它的任意一个方法和属性:这种动态获取的信息以及动态调用对象的方法的功能称为Java语言的反 ...
- synchronized 关键字
synchronized 多用于并发不高并且需要单线程运行的地方.比如你有一个A方法,你在方法上加了synchronized修饰.那么两个人同时去调用这个方法的时候不是并行的,是抢占的,谁先抢到资源谁 ...
- 回溯算法————n皇后、素数串
回溯就是算法是搜索算法中一种控制策略,是一个逐个试探的过程.在试探的过程中,如果遇到错误的选择,就会回到上一步继续选择下一种走法,一步一步的进行直到找到解或者证明无解为止. 如下是一个经典回溯问题n皇 ...