根据另一个下拉列表填充下拉列表 [英] Populate Dropdown list based on another dropdown list

查看:78
本文介绍了根据另一个下拉列表填充下拉列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
根据在另一个下拉列表中的选择填充一个下拉列表

我的aspx页面上有3个下拉列表.第一个使用4个值进行硬编码.例如,以编程方式填充第二个.如果我在第一个下拉列表中选择"Product1",则第二个下拉列表应填充"Model1_1","Model1_2"之类的值.如果我选择"Product2",则第二个下拉列表将填充"Model2_1","Model2_2".

能给我一些帮助吗?

解决方案

1在第一个DropDownList1上设置 AutoPostBack ="true" 并添加 OnSelectIndexChanged ="YourDelegate" ./p>

2在您发布数据的委托中,将第二个DropDownList2绑定到前缀SelectedValue

 受保护的void DropDownList_SelectedIndexChanged(对象发送者,EventArgs e){var value = DropDownList1.SelectedValue;if(value =="Product1"){....}否则if(value =="Product2"){....}} 

Possible Duplicate:
Populate one dropdown based on selection in another

I have 3 Dropdown list on my aspx page. First one is hard coded with 4 values. The second one should be populated programatically, for ex. if I select "Product1" in first dropdown, then second dropdown should be populated with values like "Model1_1", "Model1_2". If I select "Product2" then the second dropdown is populated with "Model2_1", "Model2_2").

Could you give me some help ?

解决方案

1 Set AutoPostBack="true" on first DropDownList1 and add OnSelectIndexChanged="YourDelegate".

2 In your delegate when you post data, bind your second DropDownList2 with prefix SelectedValue

 protected void DropDownList_SelectedIndexChanged(object sender, EventArgs e)
 {
   var value =  DropDownList1.SelectedValue;
   if(value == "Product1")
   { 
    ....      
   }
   else if(value == "Product2")
   { 
    ....      
   }
 }

这篇关于根据另一个下拉列表填充下拉列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆