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. unity中全屏背景图缩放

    using UnityEngine; using System.Collections; public class BgPicScript : MonoBehaviour { // Use this ...

  2. uva147 Dollars ——完全背包

    link:http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem& ...

  3. iOS的URL处理

    前两天处理iOSapp过程中(我是用swift语言写的,资料较少),被一个“字符串”搞了一晚上的时间到第二天才处理好,在此记下,望见过此文的学生有一天遇到该情况能三分钟搞定不浪费时间: 先看如下代码 ...

  4. ✡ leetcode 163. Missing Ranges 找出缺失范围 --------- java

    Given a sorted integer array where the range of elements are in the inclusive range [lower, upper], ...

  5. 论文笔记之:A CNN Cascade for Landmark Guided Semantic Part Segmentation

    A CNN Cascade for Landmark Guided Semantic Part Segmentation  ECCV 2016 摘要:本文提出了一种 CNN cascade (CNN ...

  6. 各种Linux发行版本优缺点对比[转]

    转自:http://www.zzbeidaqingniao.com/linux/20100127/1495.html linux最早由Linus Benedict Torvalds在1991年开始编写 ...

  7. javascript中的闭包解析

    学习javaScript已经有一段时间了,在这段时间里,已经感受到了JavaScript的种种魅力,这是一门神奇的语言,同时也是一门正在逐步完善的语言,相信在大家的逐步修改中,这门语言会逐步的完善下去 ...

  8. IOCP之客户端及消息传递

    上篇说到IOCP的精简实现,这篇来讲IOCP客户端和消息传递 在ConnectEx代码之前,CreateIoCompletionPort的第三个参数,把socket句柄+0x01000000作为传递 ...

  9. MYSQL EXPLAIN 很慢的原因

    今天同事在查看一个SQL的执行计划的时候,EXPLAIN语句跑了2分钟.SQL命令类似: SELECT * FROM (SELECT USERID,COUNT(*) FROM TBNAME GROUP ...

  10. java短信接口

    一.背景 从是Java一直想做一个跟生活联系特别紧密的东西,比如短信.邮箱.电话什么的一直是我感兴趣的,可是楞是当初没有头绪弄,恰巧今天公司在做一个 webrtc的视频会议的软件,刚好有短信这个需求, ...