如何根据另一个组合框的选定值填充组合框 [英] how to fill a combobox based on selected value of another combobox

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

问题描述

我想使用两个组合框.
这两个组合框数据都从数据库填充.

我希望第二个组合框根据第一个组合框的选定值进行填充.



请提供正确的代码.

I want to use two comboboxes.
Both combobox data fill from database.

I want second combobox to populate based on selected value from the first combobox.



Please give proper code.

推荐答案

在第一个的selectedItemChanged事件上,使用第一个组合的selectedValue作为参数调用数据库调用,以加载第二个组合的值.

例如:


On selectedItemChanged event of the first you load the values of the second combo, using the selectedValue of the first as parameter to your database call.

Ex:


protected void ddlCity_SelectedIndexChanged(object sender, System.EventArgs e)
{
    
        ddlStreet.DataSource = Dal.GetStreetsByCity(ddlCity.SelectedItem.Text);
        ddlStreet.DataTextField = "streetName";
        ddlStreet.DataValueField = "idStreet";
        ddlStreet.DataBind();
        
    }
}


Krauze写道:

请给正确的代码...

pls give proper code...

请不要索要现成的代码.

ComboBox类具有您所需要的全部内容,而MSDN提供了完整的文档(例如,请参见

Please don''t ask for ready-to-run code.

The ComboBox class has all you need and MSDN provides full documentation (see, for instance, the example in ComboBox Class[^] overview).

:)


这篇关于如何根据另一个组合框的选定值填充组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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