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控件的更多相关文章

  1. DropDownList控件

    1.DropDownList控件 <asp:DropDownList runat="server" ID="DropDownList1" AutoPost ...

  2. DropDownList 控件不能触发SelectedIndexChanged 事件

    相信DropDownList 控件不能触发SelectedIndexChanged 事件已经不是什么新鲜事情了,原因也无外乎以下几种: 1.DropDownList 控件的属性 AutoPostBac ...

  3. c#中DropDownList控件绑定枚举数据

    c# asp.net 中DropDownList控件绑定枚举数据 1.枚举(enum)代码: private enum heros { 德玛 = , 皇子 = , 大头 = , 剑圣 = , } 如果 ...

  4. DropDownList 控件

    今天打算学习下dropdownlist控件的取值,当你通过数据库控件或dataset绑定值后,但又希望显示指定的值,这可不是简单的值绑定就OK,上网搜了一些资料,想彻底了解哈,后面发现其中有这么大的奥 ...

  5. DropDownList控件学习

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.We ...

  6. 客户端用JavaScript填充DropDownList控件 服务器端读不到值

    填充没有任何问题,但是在服务器端却取不出来下拉表中的内容.页面代码如下. <form id="form1" runat="server"> < ...

  7. DropDownList 控件的SelectedIndexChanged事件触发不了

    先看看网友的问题: 根据Asp.NET的机制,在html markup有写DropDownList控件与动态加载的控件有点不一样.如果把DropDownList控件写在html markup,即.as ...

  8. 在FooterTemplate内显示DropDownList控件

    如果想在Gridview控件FooterTemplate内显示DropDownList控件供用户添加数据时所应用.有两种方法可以实现,一种是在GridView控件的OnRowDataBound事件中写 ...

  9. asp.net mvc中使用jquery H5省市县三级地区选择控件

    地区选择是项目开发中常用的操作,本文讲的控件是在手机端使用的选择控件,不仅可以用于实现地区选择,只要是3个级别的选择都可以实现,比如专业选择.行业选择.职位选择等.效果如下图所示: 附:本实例asp. ...

随机推荐

  1. 详解Objective-C runtime

    感谢翻译小组成员wingpan热心翻译.本篇文章是我们每周推荐优秀国外的技术类文章的其中一篇.如果您有不错的原创或译文,欢迎提交给我们,更欢迎其他朋友加入我们的翻译小组(联系qq:2408167315 ...

  2. 腾讯优测| 让Android屏幕适配开发更简单-Google百分比布

    文/腾讯优测工程师 吴宇焕 腾讯优测优社区干货精选~ 相信开发同学都被安卓设备碎片化的问题折磨过,市面上安卓手机的主流屏幕尺寸种类繁多,给适配造成很大的困难.就算搞定了屏幕尺寸问题,各种分辨率又让人眼 ...

  3. python 函数可变长参数

    python中的可变长参数有两种: 一种是非关键字参数(*元组),另一种是关键字参数(**字典) 非关键字可变长参数: """ 非关键字可变参数,一个星号作为元组传入函数 ...

  4. 以ls命令为实例介绍命令基本格式

    登陆Linux命令行会显示一行字符,例如[root@localhost  ~ ]#, 其中root表示当前登陆用户,localhost表示主机名,~显示的是当前路径,(-表示当前用户的家目录),#表示 ...

  5. Chrome渲染Transition时页面闪动Bug

    前段时间,有同事和会员反馈使用Chrome访问淘宝首页会出现画面闪动的现象,但是我在Mac和Win下面的Chrome都无法重现这个问题,后来重装了一遍Win7下的Chrome Beta版本,终于重现了 ...

  6. Linux系统常用命令

    查找在linux的软件装到哪上面去了,用这个命令dpkg用dpkg命令,比如查pcmanfm这个软件安装到什么地方了用 dpkg -L pcmanfm

  7. NodeJS的小应用

    server.js: //引入require 模块 var http=require('http'); //创建服务器 http.createServer(function(request,respo ...

  8. iPhone SlideShow

    If you found any question when you use the Slideshow, don't hesitate to leave a message please.

  9. MyBatis学习总结(七)——Mybatis缓存

    一.MyBatis缓存介绍 正如大多数持久层框架一样,MyBatis 同样提供了一级缓存和二级缓存的支持 一级缓存: 基于PerpetualCache 的 HashMap本地缓存,其存储作用域为 Se ...

  10. Hive操作表部分总结

    创建表: create table tableName(time INT,userid BIGINT,url STRING,ip STRING COMMENT 'IP Address of the U ...