Dropdown List

alimcm1

New Member
I have two dropdown list, the first is product code and the second is the extension of a product code, there is many extension to one product code. Now what I would like to do is when the first dropdown is selected the second dropdown is filled with the extension from the selected product code. I have written some code in the product code selectindex change event:<BR><BR>Private Sub ddlPCode_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles ddlPCode.SelectedIndexChanged<BR> If Not IsPostBack = False Then<BR> ddlExt.Enabled = True<BR> Dim strSelect As String<BR> strSelect = "Select Extension from RFQPCodeExt "<BR> strSelect &= "Where Extension='" & ddlPCode.SelectedItem.Text & "'"<BR><BR> Dim MyConn As New SqlClient.SqlConnection(Me.SqlConnection1.Connecti onString)<BR> Dim MyCmd As New SqlClient.SqlCommand(strSelect, MyConn)<BR> Dim reader As SqlClient.SqlDataReader<BR><BR> Try<BR> MyConn.Open()<BR> reader = MyCmd.ExecuteReader<BR> Do While reader.Read<BR> Dim NewExt As New ListItem()<BR> NewExt.Text = reader("Extension")<BR> NewExt.Value = http://aspmessageboard.com/archive/index.php/reader("Extension")<BR> ddlExt.Items.Add(NewExt)<BR> Loop<BR><BR> reader.Close()<BR><BR> Catch err As Exception<BR> Label1.Text = "ERROR in updating an RFQ. "<BR> Label1.Text &= err.Message<BR> Finally<BR> If (Not MyConn Is Nothing) Then<BR> MyConn.Close()<BR> End If<BR> End Try<BR> End If<BR> End Sub<BR><BR>Am I giong in the right direction or can someone help me get started. thankyou for your time and help.Looks ok. Does it work? What happens? I am wondering about this line though:<BR> If Not IsPostBack = False Then <BR>Why not just:<BR> If IsPostBack ThenI didn't set the AutoPostBack attribute on the dropdown list box, it works quite well now. thanks for responding anyway
 
Back
Top