前台代码:

<asp:DropDownList ID="DropDownList1" runat="server" Style="width: 200px; height: 30px" AutoPostBack="true" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">

</asp:DropDownList>

<asp:DropDownList ID="DropDownList2" runat="server" Style="width: 200px; height: 30px" AutoPostBack="true">

</asp:DropDownList>

后台代码

public void Bindate()

{

DropDownList1.DataSource = comBLL.GetModelList("state=1");

DropDownList1.DataTextField = "Name";

DropDownList1.DataValueField = "id";

DropDownList1.DataBind();

}

public void BindTo()

{

var selected = DropDownList1.SelectedValue;

List<Model.Person.pmDepartment> ds = opmDepartmentBLL.GetModelList(" state=1 and CompanyId=" + selected);

DropDownList2.DataSource = ds;

if (ds == null || ds.Count < 0)

{

DropDownList2.Items.Clear();

}

else

{

DropDownList2.DataTextField = "Name";

DropDownList2.DataValueField = "id";

DropDownList2.DataBind();

}

}

protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)

{

var selected = DropDownList1.SelectedValue;

if (string.IsNullOrEmpty(selected))

{

DropDownList2.Items.Clear();

}

else

{

BindTo();

}

}

页面加载:

protected void Page_Load(object sender, EventArgs e)

{

if (!LoadQueryString())

return;

if (!IsPostBack)

{

//调用方法

Bindate();

BindTo();

DropDownList1.SelectedValue = opmUserInfo.CompanyId.ToString();

DropDownList2.SelectedValue = opmUserInfo.DepartmentId.ToString();

}

}

转载于:https://www.cnblogs.com/shanshuiYiCheng/p/7505648.html

DropDownList联动相关推荐

  1. 实现无刷新DropDownList联动效果

    在做一个文章添加功能时,想在选择大类后,自动将其所属二级小类显示出来,使用DropDownList的SelectedIndexChanged事件可以很容易实现,但每次选择后页面总要刷新一次,让人感觉很 ...

  2. GridView类容器中的DropDownList联动

    - 实例说明: 部门,与部门人员2个下拉框. (1)前台码 <EditItemTemplate> 部门: <asp:DropDownList ID="ddlstdepart ...

  3. YII实现dropDownList 联动事件

    因功能需求,需要用到联动,特此记录分享 一.视图中 <div class="main-form"><?php $form = ActiveForm::begin( ...

  4. java dropdownlist_实现无刷新DropDownList联动效果

    在做一个文章添加功能时,想在选择大类后,自动将其所属二级小类显示出来,使用DropDownList的JavaScript 在做一个文章添加功能时,想在选择大类后,自动将其所属二级小类显示出来,使用Dr ...

  5. GridView中DropDownList联动

    1.在GridView模板列中添加DropDownList并设置AutoPostback属性为true. 2.再在DropDownList的SelectedIndexChanged事件里写下面几句话. ...

  6. [转贴]无刷新的2个DropDownList联动

        <script language="javascript"> <!-- var where = new Array(36);  function come ...

  7. ajax 如何使 dropdownlist 无刷新,Jquery实现无刷新DropDownList联动实现代码

    先看HTML,我们引用Jquery,放两个DropDownList: #ddlEmployeeCars { display:none; position:absolute; top:50px; lef ...

  8. 下拉式菜单在GridView编辑时联动选择

    父子下拉式菜单DropDownList在GridView编辑时联动选择. 本Demo从添加时的父子DropDownList联动选择,以及在GridView的编辑时联动功能实现. 文件格式:.wmv;大 ...

  9. html.dropdownlist 样式,Html.DropDownList

    //获取直属父级列表 var parents = _MemberEditDTOService.GetParents(); var parentsItems = parents.Result.Selec ...

最新文章

  1. 如何实现手机自动适应网页
  2. Jupyter安装r内核
  3. 【读书笔记】代码可为维护性标准(一)
  4. UA MATH524 复变函数14 Laurent级数
  5. 【转】深入剖析iLBC的丢包补偿技术(PLC)
  6. oracle em 空白,Oracle em中出现按钮乱码的实际解决方案
  7. proxy connect abort处理方法_Java代理设计模式(Proxy)的几种具体实现
  8. python raise_python raise 使用方法
  9. JVM—垃圾回收GC算法
  10. Linux kernel 内核升级与降级实战
  11. 为什么要重构(why)?
  12. C/C++作用域运算符::
  13. 【压力测试】用JMeter进行百科网站压力测试
  14. this的三种常见用法
  15. Conflux人物志-伍鸣博士:好奇心是我探索未知世界的动力
  16. 计算机怎么取消脱敏设置,脸过敏如何治疗 脸部快速脱敏的妙招
  17. 人工智能领域专业术语合集
  18. 跨境电商系列 | 防范第三方脚本对数据隐私与安全的侵蚀
  19. win10向VMware中的win7传文件
  20. easyui datebox时间控件改为年月视图,值也为年月

热门文章

  1. 中国工程院谭建荣:人工智能应用得再好,最核心的算法不行,创新能力就不行
  2. 独角兽也未能幸免,2019“阵亡”新经济公司大盘点
  3. Python的pycurl库升级升级失败的解决方法
  4. TensorFlow 完整的TensorFlow入门教程
  5. 变量置换方式linux,Shell变量测试与内容置换
  6. adcclk最大_STM32 ADC转换时间
  7. 操作系统常用调度算法
  8. 为什么重复值高的字段不能建索引(比如性别字段等)
  9. 025_Tree树形控件
  10. php异步方案,PHP的异步实现方式