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. meta-analysis 到底是什么个意思类?

    背景 科学研究应建立于许多实验结果的重复之上,除了少数新发现外,单个实验结果很难对科学的发展作出极为显著的贡献.所以为了阐明某一主题,在许多科学领域有众多研究者在对不同的实验对象或对同一对象在不同的实 ...

  2. P,NP,NPC,NPC-HARD

    P: 能在多项式时间内解决的问题 NP: 不能在多项式时间内解决或不确定能不能在多项式时间内解决,但能在多项式时间验证的问题 NPC: NP完全问题,所有NP问题在多项式时间内都能约化(Reducib ...

  3. 一个基于ANTLR 4的布尔表达式语句解释器的实现

    Reference The Definitive ANTLR 4 Reference, 2nd Edition. 0 Features labeled grammar definition, i.e. ...

  4. ctype.h / cctype 中的字符函数

    函数名称 返回值 isalnum() 字母或数字 isalpha() 字母 iscntrl() 控制字符 isdigit() 数字(1 ~ 9) isgraph() 除空格之外的打印字符 islowe ...

  5. JSONObject转换JSON--将Date转换为指定格式

    项目中,经常会用JSONObject插件将JavaBean或List<JavaBean>转换为JSON格式的字符串,而JavaBean的属性有时候会有java.util.Date这个类型的 ...

  6. WorldChat.lua --世界聊天

    print(">>Script: Wolrd Chating.") local SAY=" "--普通聊天 --联盟阵营 --部落阵营 local ...

  7. jquery选择器之基本筛选器

    HTML示例代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset=" ...

  8. arcgis server 10.2安装后,忘记Manager的用户名和密码

    arcgis server 10.2安装完毕后,需要创建站点,创建站点时,填写管理站点的用户名和密码.自己不小心,创建完毕后,给忘记了用户名和密码.求助Esri,解决方法如下: (1)找到arcgis ...

  9. VS2010快捷键大全

    VS2010版快捷键 Ctrl+E,D ----格式化全部代码 Ctrl+E,F ----格式化选中的代码 CTRL + SHIFT + B生成解决方案 CTRL + F7 生成编译 CTRL + O ...

  10. Mathematica 计算矩阵的伴随矩阵

    AdjointMatrix[M_] := Module[{Ma, B, n, i, j},    Ma = Minors[M];    B = Ma;    n = Dimensions[M][[1] ...