三级联动---DropDownList控件
AutoPostBack属性:意思是自动回传,也就是说此控件值更改后是否和服务器进行交互
比如Dropdownlist控件,若设置为True,则你更换下拉列表值时会刷新页面(如果是网页的话),设置为flase就不会刷新了(也就是false时不和服务器交互) 列如:要操作ChinaStates表, 先连接数据库--三大类,ChinaDA类:如下:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data.SqlClient; /// <summary>
/// ChinaDA 的摘要说明
/// </summary>
public class ChinaDA
{
private SqlConnection _conn ;
private SqlCommand _cmd;
private SqlDataReader _dr;
public ChinaDA()
{
_conn = new SqlConnection("server=.;database=mydb;user=sa;pwd=100867");
_cmd = _conn.CreateCommand();
} public List<ChinaStates> Select(string PC)//只查询 父级(parentareacode)
{
_cmd.CommandText = "select * from ChinaStates where ParentAreaCode=@parentareacode";
_cmd.Parameters.Add("@parentareacode",PC);
_conn.Open();
_dr = _cmd.ExecuteReader();
List<ChinaStates> list = new List<ChinaStates>();
if (_dr.HasRows)
{
while (_dr.Read())
{
ChinaStates cs = new ChinaStates();
cs.AreaCode=_dr[].ToString();
cs.AreaName=_dr[].ToString();
cs.ParentAreaCode=_dr[].ToString();
list.Add(cs);
}
}
_conn.Close();
return list;
}
}
aspx.cs里:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls; public partial class sanji : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{//下面做了方法来这里调用,调用三次
Bind(DropDownList1,new ChinaDA().Select(""));//中国下的
Bind(DropDownList2,new ChinaDA().Select(DropDownList1.SelectedValue));//取省下面的值
Bind(DropDownList3,new ChinaDA().Select(DropDownList2.SelectedValue));//取市下面的值 }
DropDownList1.SelectedIndexChanged += DropDownList1_SelectedIndexChanged;//做委托
DropDownList2.SelectedIndexChanged += DropDownList2_SelectedIndexChanged;
} void DropDownList2_SelectedIndexChanged(object sender, EventArgs e)
{
// 列表控件里的值在信息发往服务器时发生的变化,
Bind(DropDownList3, new ChinaDA().Select(DropDownList2.SelectedValue));//取市下面的值-区
} void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
Bind(DropDownList2, new ChinaDA().Select(DropDownList1.SelectedValue));//取省下面的值-市
Bind(DropDownList3, new ChinaDA().Select(DropDownList2.SelectedValue));//取市下面的值-区
} //填充三个下拉的内容,做集合 绑定数据
private void Bind(DropDownList dd1, List<ChinaStates> list)
{
dd1.DataSource = list;
dd1.DataTextField = "AreaName";
dd1.DataValueField = "AreaCode";
dd1.DataBind();//绑定到...
} }
三级联动---DropDownList控件的更多相关文章
- DropDownList控件
1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...
- DropDownList 控件不能触发SelectedIndexChanged 事件
相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...
- c#中DropDownList控件绑定枚举数据
c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...
- DropDownList 控件
今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...
- DropDownList控件学习
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...
- 客户端用JavaScript填充DropDownList控件 服务器端读不到值
填充没有任何问题,但是在服务器端却取不出来下拉表中的内容.页面代码如下. <form id="form1" runat="server"> < ...
- DropDownList 控件的SelectedIndexChanged事件触发不了
先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...
- 在FooterTemplate内显示DropDownList控件
如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...
- asp.net mvc中使用jquery H5省市县三级地区选择控件
地区选择是项目开发中常用的操作,本文讲的控件是在手机端使用的选择控件,不仅可以用于实现地区选择,只要是3个级别的选择都可以实现,比如专业选择.行业选择.职位选择等.效果如下图所示: 附:本实例asp. ...
随机推荐
- Toad快速入门
Toad快速入门 在实际中,Toad的用户很少用到其强大的新特性,同时新用户的摸索式熟悉Toad往往花费更多的时间.为此,铸锐数码为每个新购买Toad客户,提供两人次的在线培训服务,帮助客 ...
- libevent库1.4升级到2.0时无法flush的解决办法
libevent的接口兼容性做的还算不错,基本上替换一下就转到新版本了.但是,强制flush数据的时候出了问题.目前的应用场景是,遇到顶号登录这种情形,先用bufferevent_write向客户端发 ...
- springboot系列之-helloword入门
一. What: Spring Boot是什么?以1.4.3.RELEASE为例,官方介绍为:http://docs.spring.io/spring-boot/docs/1.4.3.RELEASE/ ...
- 机械键盘那些事[我用过的minila Filco cherry 3494 阿米洛87]
用过几月下来.最终现在还能流畅使用的,就剩下3494 跟 minila了. 想起购买的初衷.cherry是泰斗,红轴轻柔,所以三把全红轴. 之后,觉得携带外出不方便,所以就又入了个MINILA. 再后 ...
- bootstrap-8
基本按钮: bootstrap框架V3.x版本的基本按钮和V2.x版本的基本按钮一样,都是通过类名.btn来实现,不同的是V3.x版本要简约很多,去除V2.x版本中的大量的CSS3的部分特效. 默认按 ...
- 如何取Android设备日志
安装Android SDK 运行 adb 命令 adb devices 查看链接的设备 adb logcat 日志相关
- 如何使Android应用开机时自动启动
先记下来,主要是继承BroadcastReceiver实现.还有开机自动启动service的,好像是继承 IntentReceiver,不知道有什么不一样,有时间试试. 一: 简单 Android也有 ...
- PHP 载入图像 imagecreatefrom_gif_jpeg_png 系列函数
imagecreatefrom 系列函数用于从文件或 URL 载入一幅图像. 载入图像 imagecreatefrom 系列函数用于从文件或 URL 载入一幅图像,成功返回图像资源,失败则返回一个空字 ...
- 3D Touch集成过程整理
1.集成App图标按压快速打开某个功能 在AppDelegate.m中加入以下三个东西 在启动方法里加入3D Touch菜单 - (BOOL)application:(UIApplication *) ...
- php返回json,xml,JSONP等格式的数据
php返回json,xml,JSONP等格式的数据 返回json数据: header('Content-Type:application/json; charset=utf-8'); $arr = a ...