组合框问题 [英] Combo boxes problem

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

问题描述


我有两个组合框.一个包含部门列表,第二个包含操作列表.每个部门都有自己的业务.我需要用与在第一个组合框中选择的部门相关的操作来填充第二个组合框中的帮助.我正在使用Visual Studio 2005(Visual Basic).感谢您的帮助.

Hi,
I have two combo boxes. One contains list of departments and second list of operations. Each department has its own operations. I need help with filling second combo box with operations that are related to department selected in first combo box. I''m using Visual Studio 2005(Visual Basic). I appreciate any kind of help.
Thanks!

推荐答案

您应该考虑购买一本基础书籍并阅读,或者阅读我有关如何使用google的文章.

组合框上有一个更改选择的事件.组合框具有一个显示成员和一个值成员.存储您需要查找第二个组合的数据的ID,该ID在第一个组合的显示成员旁边.事件触发时,查找ID,从您的数据库中读取数据,并用它填充第二个组合框.
You should consider buying a basic book and reading it, or perhaps reading my article on how to use google.

There''s a selection changed event on the combo boxes. The combo boxes have a display member and a value member. Store the id you need to look up the data for the second combo, next to the display members in the first. When the event fires, look up the id, read the data from your DB, and populate the second combo box with it.


示例代码,例如
考虑两个数据视图dvDeptData,dvOpData从数据库获取数据.
example code like
consider two Dataviews dvDeptData, dvOpData get data from Database.
ddlDepartment.Datasource = dvDeptData;
ddlDepartment.Databind();

//Filter Operations Data with DeptID
dvOpData.RowFilter = "DeptID=" + ddlDepartment.SelectedValue;

ddlOperations.Datasource = dvOpData;
ddlOperations.Databind();


现在,您有了两个下拉控件.绑定第一个组合框,其datavalue为id,文本为某些文本字段.现在将第一个组合框的autopostback属性设置为true,以便将其回发到服务器.
因此,现在在firstgird的selectedindexchanged事件中编写绑定第二个组合的代码,以使用以下查询来进行数据绑定...

select * from sometable where someid=" + combo2.selectedvalue;


您将得到结果.
Now, you have two dropdown controls. Bind 1st combo box with datavalue as id, and text as some textfield. now set autopostback property of the fist combo box to true, so that it will make postback to the server.
so now in the selectedindexchanged event of the firstgird write your code of binding the 2nd combo, for databinding use query like this...

select * from sometable where someid=" + combo2.selectedvalue;


you will get your result.


这篇关于组合框问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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