本文介绍了国家,州,城市使用窗口形式绑定到组合框的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们.
我想将国家,州,城市绑定到combobox.我所做的是在page_load事件中将国家名称绑定到combobox1.下面的代码用于在页面加载事件中绑定国家/地区
阶段(1)

Hi friends.
I want to bind country,state,city to combobox.what i have done is country name has been bound to combobox1 at the page_load event. The below code for binding country on the page load event
stage(1)

int i = 3;
            DataTable dt = ibl2.combo1(i);
            countrycombo.DataSource = dt;
            countrycombo.DisplayMember =Convert.ToString( dt.Columns["Country_name"]);
            countrycombo.ValueMember = Convert.ToString(dt.Columns["Country_id"]);


国家名称已成功绑定到contrycombobox.
阶段(2)
下面的代码在combobox1_selectedIndexChandged事件中绑定状态名


country name successfully bound to contrycombobox.
stage(2)
The below code for bind statename at combobox1_selectedIndexChandged event

private void countrycombo_SelectedIndexChanged(object sender, EventArgs e)
       {

           string countyname = Convert.ToString( countrycombo.SelectedItem);
           DataTable ds = ibl2.statecombo(countyname);
           statecombo.DataSource = ds;
           if (ds != null)
           {
               statecombo.DisplayMember = Convert.ToString(ds.Columns["State_name"]);
               statecombo.ValueMember = Convert.ToString(ds.Columns["State_id"]);
           }




问题发生在第二阶段.根据国家/地区名称将状态名称绑定到combobox2(statecombo).
问题是,在combobox1_selectedIndexchanged事件中将状态名称绑定到combobox2时,它会从国家/地区名称中获取空值.当我使用f11键跟踪此过程时,combox1_selectedItem事件会在页面中的代码




The problem occurrs on the second stage.Binding the state name to combobox2(statecombo) based on the country name.
The problem is when binding the statename to combobox2 at the combobox1_selectedIndexchanged event it take null value from country name.when i trace this process using f11 key, combox1_selectedItem event occur after the code

countrycombo.DataSource = dt;

自身加载后发生,因此它不会占用任何内容国家组合框中的值.我需要的是,当我选择国家/地区名称后,应该会发生此事件.我该怎么办.

in the page load itself so that it doesnt take any value from country combo box. what i need is this event should be occur after when i select the name of the country. what can i do.

推荐答案



这篇关于国家,州,城市使用窗口形式绑定到组合框的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 16:12
查看更多