基于第一组合框上的索引过滤第二组合框 [英] filtering the second combobox based on index on the first combobox
问题描述
Public Sub FiltercmbSubCategory()
Dim sqlconn As New SqlClient.SqlConnection
sqlconn.ConnectionString = "server = SKPI-APPS1;" & _
"Database = EOEMS;integrated security=true"
Dim sqlcommand As SqlCommand
sqlconn.Open()
Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentSubCategory WHERE SUBCAT_ID = '" & cmbCategory.Text & "'", sqlconn)
Dim dt As New DataTable
da.Fill(dt)
cmbCategory.DataSource = dt
cmbCategory.DisplayMember = "SUBCAT_Name"
cmbCategory.ValueMember = "SUBCAT_ID"
sqlconn.Close()
End Sub
当我把这个代码放在窗体加载事件时,第一个组合框上的数据消失了
,当我把这个代码放在index_changed第一个组合框
when i put this code on the form load event the data on the first combo box dissappears also when i put this code on the index_changed of the first combobox
但是当我注释这个代码时,它会在组合框1中再次显示记录
but when i commented this code it displays the records again in combobox 1
根据CATEGORY_COMBOBOX
i need to filter the SUB_CATEGORY_COMBO_BOX based on the CATEGORY_COMBOBOX
推荐答案
绑定您的第一个组合框:
Bind your first combobox inside:
if (!Page.IsPostBack)
{
// Bind combobox1 code here;
}
现在,在selectedindexchange上调用绑定子类别组合的代码。
Now, on selectedindexchange call the code for binding subcategory combo.
此外,再次查看您的代码:
Also, have look on your code again:
Dim da As New SqlDataAdapter("SELECT * FROM tblOfficeEquipmentSubCategory WHERE SUBCAT_ID = '" & cmbCategory.Text & "'", sqlconn)
Dim dt As New DataTable
da.Fill(dt)
cmbCategory.DataSource = dt
cmbCategory.DisplayMember = "SUBCAT_Name"
cmbCategory.ValueMember = "SUBCAT_ID"
在此代码中,您将传递 cmbCategory.Text
作为参数绑定相同的下拉菜单 cmbCategory
。我想你在这里错过了第二个下拉菜单。可能我不正确,但似乎这样。
In this code you are passing cmbCategory.Text
as paramater for binding same dropdown cmbCategory
. I think you have missed your second dropdown here. May be I am not correct but, it seems like that.
这篇关于基于第一组合框上的索引过滤第二组合框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!