-
May 13th, 2021, 05:14 AM
#1
Thread Starter
New Member
Cascading dropdownlist
Hi All, I'm trying to create a web based form. couple of fields I need it as cascading. First list is is GP Surgery and second list is GP Name. GP Surgery is a table from SQL server and GPName is a stored procedure. What I want is, when I select a GP Surgery, I want the second list to show only the GPs that work in the selected GP Surgery.
Here is the code iI used dto get the GP Surgeries - THIS WORKS FINE
Public Function PopulateGPSurgeryDropdown()
Dim costrnBedBureau = ConfigurationManager.ConnectionStrings("Servername").ConnectionString
Try
DDLGPSurgery.Items.Clear()
Dim conGPSurgery As New SqlConnection(costrnBedBureau)
'Populate GPSurgery drop down list
Dim sqlString As String = "SELECT [Organisation Code],[Organisation Name]FROM [Server_Test].[dbo].[General Medical Practice] order by [Organisation Name] asc"
Dim cmdGetGPSurgery As SqlCommand = New SqlCommand(sqlString, conGPSurgery)
cmdGetGPSurgery.CommandType = CommandType.Text
conGPSurgery.Open()
Dim drGPSurgery As SqlDataReader
drGPSurgery = cmdGetGPSurgery.ExecuteReader
DDLGPSurgery.DataSource = drGPSurgery
DDLGPSurgery.DataTextField = "Organisation Name"
DDLGPSurgery.DataValueField = "Organisation Code"
DDLGPSurgery.DataBind()
conGPSurgery.Close()
DDLGPSurgery.Items.Insert(0, "")
cmdGetGPSurgery.Dispose()
Catch ex As Exception
' HandleSystemException(System.Reflection.MethodBase.GetCurrentMethod.DeclaringType, System.Reflection.MethodBase.GetCurrentMethod(), ex)
End Try
End Function
Here is the code i use for GPName: THIS DOESNT populate the list.
Public Function PopulateGPNameDropdown(ByRef DDLGPName As Web.UI.WebControls.DropDownList, ByVal lngOrganisationcode As Char)
DDLGPName.Items.Clear()
DDLGPName.Items.Add(New ListItem("--Select GP--", ""))
Dim constrnBedBureau = ConfigurationManager.ConnectionStrings("Server").ConnectionString
'Update the GPName list.
Try
DDLGPName.Items.Clear()
Dim conGPName As New SqlConnection(constrnBedBureau)
Dim cmdGetGPName As SqlCommand = New SqlCommand("[dbo].[usp_GPName]", conGPName) With {
.CommandType = CommandType.StoredProcedure
}
Dim paramParent As SqlClient.SqlParameter
paramParent = New SqlParameter
paramParent.ParameterName = "@OrganisationCode"
paramParent.SqlDbType = SqlDbType.Text
paramParent.Value = lngOrganisationcode
cmdGetGPName.Parameters.Add(paramParent)
conGPName.Open()
Dim drGPName As SqlDataReader
drGPName = cmdGetGPName.ExecuteReader
DDLGPName.DataSource = drGPName
DDLGPName.DataTextField = "FullName"
DDLGPName.DataValueField = "GP.GP_Nat_Code"
DDLGPName.DataBind()
conGPName.Close()
Catch ex As Exception
'HandleSystemException(System.Reflection.MethodBase.GetCurrentMethod.DeclaringType, System.Reflection.MethodBase.GetCurrentMethod(), ex)
End Try
End Function
Protected Sub DDLGPSurgery_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLGPSurgery.SelectedIndexChanged
PopulateGPNameDropdown()
End Sub
Im' new to programming, so im at a clueless on what is wrong.
Please advice.
-
May 13th, 2021, 07:58 AM
#2
Re: Cascading dropdownlist
Your sub that calls the stored procedure: PopulateGPNameDropdown is expecting two paramters:
Code:
Public Function PopulateGPNameDropdown(ByRef DDLGPName As Web.UI.WebControls.DropDownList, ByVal lngOrganisationcode As Char)
But when you call it, you don't give it any:
Code:
PopulateGPNameDropdown()
That's why it isn't working. honestly I'm a bit surprised you're not getting an error. You need to pass it the DropDownList you plan to populate, and the Id of the selected item from the parent drop down.
-tg
-
May 13th, 2021, 08:04 AM
#3
Thread Starter
New Member
Re: Cascading dropdownlist
Originally Posted by techgnome
Your sub that calls the stored procedure: PopulateGPNameDropdown is expecting two paramters:
Code:
Public Function PopulateGPNameDropdown(ByRef DDLGPName As Web.UI.WebControls.DropDownList, ByVal lngOrganisationcode As Char)
But when you call it, you don't give it any:
Code:
PopulateGPNameDropdown()
That's why it isn't working. honestly I'm a bit surprised you're not getting an error. You need to pass it the DropDownList you plan to populate, and the Id of the selected item from the parent drop down.
-tg
Hi, Thank you for your response. so how does the code look like? I'm not too sure what to put to be honest. And no, I didnt get any errors. Thanks
-
May 13th, 2021, 08:25 AM
#4
Thread Starter
New Member
Re: Cascading dropdownlist
I've changed it to this.
Protected Sub DDLGPSurgery_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DDLGPSurgery.SelectedIndexChanged
PopulateGPNameDropDown(Me.DDLGPName, Me.DDLGPSurgery.SelectedItem.Value)
End Sub
But it still doesnt populate the relevant drop down.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|