Dependent Listbox problem

Results 1 to 2 of 2

Thread: Dependent Listbox problem

  1. #1
    Join Date
    Dec 1969

    Default Dependent Listbox problem

    Hi,<BR><BR>I have a dependent listbox that isn&#039;t working the way it&#039;s suppose to. Instead of showing the information that relates to the first listbox it shows all the information from the table that acts as the datasource. For example, if someone picks Contract Section 1 from the first listbox, only the subsections of that contract are to appear in the second listbox. Unfortunately, all the subsections of each contract are appearing. Can anybody look at the code and see what I&#039;m doing wrong.<BR><BR>Here&#039;s the control code:<BR>&#060;asp:DropDownList id="ddlContractSubSection" runat="server" DataValueField="SectionID" DataTextField="list" Visible="False"&#062;&#060;/asp:DropDownList&#062;<BR><BR>Here&#039;s the code for the second list box:<BR>Public Sub ddlContractSection_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlContractSection.SelectedIndexChanged<BR> &#039; Grab the value of the Selected item in the Listbox Control<BR> Dim ContractID As Integer = ddlContractSection.SelectedItem.Value<BR> Dim documents As New ASPNetPortal.GrievanceDB()<BR><BR> Dim DR As SqlDataReader = documents.GetATAContractSubSection(ContractID)<BR> <BR> &#039; Bind the DataReader <BR> ddlContractSubSection.DataSource = DR<BR><BR> &#039; If we have records the display a " Please select one" default option.<BR> &#039; Otherwise display a "No Subsections for this contract section" default option<BR> If DR.Read() Then<BR><BR> ddlContractSubSection.DataBind()<BR> ddlContractSubSection.Items.Insert(0, New ListItem("&#060;-- Please select one --&#062;", ""))<BR> Else<BR><BR> ddlContractSubSection.DataBind()<BR> ddlContractSubSection.Items.Insert(0, New ListItem("&#060;-- No Subsections for this contract section --&#062;", ""))<BR> End If<BR><BR> DR.Close()<BR><BR> ddlContractSubSection.Visible = True<BR> End Sub<BR><BR>Here&#039;s my stored procedure:<BR>CREATE PROCEDURE dbo.GetATAContractSubSection<BR>(<BR> @ContractID int<BR>)<BR>AS<BR><BR>SELECT SectionName<BR><BR>AS list,<BR>SectionID<BR><BR>FROM ATAContractSections, ATASections<BR><BR>Where ATAContractSections.ContractID = ATASections.ContractID<BR><BR>ORDER BY SectionID ASC<BR>GO

  2. #2
    Join Date
    Dec 1969

    Default RE: Dependent Listbox problem

    Looking at your SPROC, we can see that your are saying, in plain english, "Give me all the records where the contract ID in the first table is equal to the contract ID in the second table". What seems to be missing is the piece that would say ".. AND where the contract ID is equal to this SPECIFIC ID (the one that was passed in). Right?

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts