Hi all, I hope I got the right forum... I can do what the subject states when the comboBox or DropDown is NOT in a gridview, as in the code below which populates the room DDL with the value that was selected in the building DDL
Protected Sub DDLbuilding_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLbuilding.SelectedIndexChanged
'Create DataTable
Dim dtRooms As New DataTable() ' - Room Numbers
dtRooms.Columns.Add("Room", Type.GetType("System.String"))
'Get Buildings for this campus
RoomTable = RoomAdapter.GetRooms(DDLbuilding.SelectedValue)
'Fill DataTable
For Each RoomRow In RoomTable
dtRooms.Rows.Add()
dtRooms.Rows(dtRooms.Rows.Count - 1)("Room") = RoomRow.Room
Next
'bind DDLroom to datatable
DDLroom.DataSource = dtRooms
DDLroom.DataBind()
End Sub
but when the comboBox or DDL is in a gridview it throws the error "Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control". Here's what I have so far for the gridview comboBox
Protected Sub cbEQName_SelectedIndexChanged(sender As Object, e As EventArgs)
'Get row index of selected comboBox
Dim gvRow As GridViewRow = CType(CType(sender, Control).Parent.Parent, GridViewRow)
Dim index As Integer = gvRow.RowIndex
'Get selected value of selected comboBox
EQname = TryCast(GVnewEquipment.Rows(index).FindControl("cbEQname"), AjaxControlToolkit.ComboBox).Text
'Get new values of next comboBox from selected value of selected comboBox
EquipmentTable = EquipmentAdapter.GetMfg(EQname)
'Create DataTable
Dim dtMfgs As New DataTable() ' - mfgs that are used by Equiptment name
dtMfgs.Columns.Add("mfg", Type.GetType("System.String"))
'Fill DataTable
For Each EquipmentRow In EquipmentTable
dtMfgs.Rows.Add()
dtMfgs.Rows(dtMfgs.Rows.Count - 1)("mfg") = EquipmentRow.mfg
Next
'create ComboBox which will represent GVnewQuipment cbMfg comboBox
Dim CB = DirectCast(GVnewEquipment.Rows(index).FindControl("cbMfg"), AjaxControlToolkit.ComboBox)
'bind cbMfg to datatable
CB.DataSource = dtMfgs
CB.DataBind()
End Sub
Any and help is greatly appreciated!!
Lee