尊敬的用户,下拉未正确加载
我的应用程序中有两个下拉列表为ddlCountry和ddlState。 我有数据库
tlbCountry
ID(PK)|国家名称
tlbState
ID(PK)| countryName | Statename的
在页面加载我已经装在ddlCountry下拉列表中的所有项目作为
sqldataadapter da=new sqldataadapter("select countryName from tlbCountry",con);
dataset ds=new dataset();
da.fill(ds);
for(int i=0;i<ds.tables[0].rows.count;i++)
ddlCountry.items.add(ds.Tables[0].Rows[i][0].toString());
当页面被加载时,高达该公司工作的罚款。 但是, 在Textchange或ddlCountry的选择更改事件上时,它会尝试从tlbStates表中获取相应状态的值,如下所示。它不工作,我做了如下,
sqldataadapter da=new sqldataadapter("select stateName from tlbState where countryName like '"+ddlCountry.selectedItem.toString()+"'",con);
dataset ds=new dataset();
da.fill(ds);
for(int i=0;i<ds.tables[0].rows.count;i++)
ddlState.items.add(ds.Tables[0].Rows[i][0].toString());
在这种情况下,它不加载ddlState下拉。
当我打开ddlCountry的autopostback时,它会在ddlState中重新加载没有值的页面。 可能是什么问题?
注意: - 我已经使用了AJAX UPDATE PANEL。
尝试在你使用'ddlCountry.selectedItem.Text'上ddlCountry –
的变化提取国家查询在调试时,直接在SQL Server中运行它并分享你的发现。 –
@Behroz调试时,我发现它不会进入ddlcountry组合中的事件函数selectedindexchanged,我尝试在ddlStates中加载状态以查看ddlCountry。我让ddlCountry的autopostback为true,那么它也没有工作 – Freelancer