Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

3 DropDownLists and AutoPostback

Status
Not open for further replies.

SonJ

Programmer
Oct 24, 2002
166
GB
Hi,

I have a page with 3 dropdown lists on them.
1)status
2)project
3)subproject

What I would like to do is, when the user selects a status in the first dropdownlist I want the second to comeback to show all the projects that have that status. When the user then picks a project I want the third to comeback with a list of subprojects that belong to the project.

I thought that having an autopostback event set to true on 1 and 2 would help me to acheive the desired result.

However, it seems to work for the first 2 dropdownlists and then fails when I try to use the same logic for the 3rd dropdown list.

The code is as follows:
Code:
	If Not Page.IsPostBack Then

            '--get statuses
            strSQL = "SELECT StatusText, StatusID FROM tblStatus WHERE isDeleted=0 ORDER BY SeqNo"
            objCmd.CommandText = strSQL
            objDR = objCmd.ExecuteReader()

            selStatus.DataSource = objDR
            selStatus.DataTextField = "StatusText"
            selStatus.DataValueField = "StatusID"
            selStatus.DataBind()

            objDR.Close()

        End If

        '--get project names
        strSQL = "SELECT ProjectName, ProjectID FROM tblProjects WHERE isSuperseded=0 "
        If selStatus.SelectedValue > 1 Then
            strSQL += " AND StatusID=" & selStatus.SelectedValue
        End If
        strSQL += " ORDER BY ProjectName"

        lblEx.Text = strSQL & &quot;<BR><BR>&quot;

        objCmd.CommandText = strSQL
        objDR = objCmd.ExecuteReader()

        selProjectName.DataSource = objDR
        selProjectName.DataValueField = &quot;ProjectID&quot;
        selProjectName.DataTextField = &quot;ProjectName&quot;
        selProjectName.DataBind()

        objDR.Close()

        '--get sub projects names
        strSQL = &quot;SELECT SProjectName, SProjectID FROM tblSProjects WHERE isSuperseded=0 &quot;
        If selProjectName.SelectedValue > 0 Then
            strSQL += &quot; AND ProjectID=&quot; & selProjectName.SelectedValue
        End If
        strSQL += &quot; ORDER BY SProjectName&quot;

        lblEx.Text += strSQL & &quot;<BR><BR>&quot;

        objCmd.CommandText = strSQL
        objDR = objCmd.ExecuteReader()

        selSProjectName.DataSource = objDR
        selSProjectName.DataValueField = &quot;SProjectID&quot;
        selSProjectName.DataTextField = &quot;SProjectName&quot;
        selSProjectName.DataBind()

        objDR.Close()

Can anyone see what I am doing wrong?

Any insights would be much appreciated.

SonD
 
I would wire up the the onSelectedIndexChange event.
Code:
  Public Sub selStatus_OnSelectedIndexChanged(ByVal source As Object, ByVal e As EventArgs)
 'code to populate next combo.
  End Sub
 
Thanks cbokowski, I figured it out as soon as I had submitted the post!

SonD
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top