Using a DropDownList in a DataGrid to update anoth

Australia

New Member
Hi,<BR><BR>I've got two DropDownLists on my Datagrid. One has Schools in it, the other has Classes. When the user changes the school, I want the other DropDownList to display Classes relevant to that School. I'm currently using the 'OnSelectedIndexChanged' event to run a Sub that updates the DataTable that my 'Classes' DropDownList is using as its DataSource using<BR><BR>DataSource="<%#objClassesTable%>" When the user changes the school<BR><BR>The Sub that is run when the user changes the selected school:<BR> <BR>Sub UpdateClasses(Sender as Object, E as EventArgs)<BR> Dim strConnection as String = "Provider=Microsoft.Jet.OLEDB.4.0;"<BR> strConnection += "Data Source=" & server.mappath("LearnMaths.mdb")<BR> dim ddlSchoolNameHolder as DropDownList<BR><BR> ddlSchoolNameHolder=dgUsers.items(CInt(lblEditInde x.text)).FindControl("ddlSchoolName")<BR><BR> Dim strSQL as String ="select fldClassID, fldClassName from tblClasses WHERE fldSchoolID=" & ddlSchoolNameHolder.SelectedItem.Value<BR> Dim objClassesDataSet as new DataSet()<BR> Dim objConnectionC as new OledbConnection(strConnection)<BR> Dim objAdapterC as new OleDbDataAdapter(strSQL, objConnectionC)<BR> objAdapterC.Fill(objClassesDataSet, "tblClasses") <BR> objClassesTable=objClassesDataSet.tables("tblClasses")<BR><BR> End Sub <BR><BR>The DataTable is definitely filled with the classes for the newly selected school but the classes available in the DropDownList remain the same! I need to somehow 're-bind' the new datatable to my 'Classes' DropDownList. Any ideas or is this impossible to do and I need a totally different method?<BR><BR>Any help is greatly appreciated!You need to call the DataBind method of the page or the control after retrieving the appropriate results with your SQL Query.<BR><BR>Hope that helps.Thanks Paul but I can't see how I can do either of your suggestions because I can't 'see' the control from the code! <BR><BR>I tried to do a<BR><BR>page.databind()<BR><BR>After the objClassesTable=objClassesDataSet.tables("tblClasses") line but all that did was to display nothing!<BR><BR>Any other ideas?
 
Back
Top