problem with onselect of a dynmically created dropdownlist

getnitha

Member
Joined
Jul 16, 2007
Messages
14
Programming Experience
1-3
hi,

i am using vb.net 2005 alomg with asp.net 2.0.
I have a textbox whixh accepts the no of dropdownlistboxes.based upon this no i am loading rows of dropdownlist
Each row contains 3 sets of dropdownlists.
On select of first one second one gets loaded and on select of second one 3rd one gets loaded.same procedure for all the rows.

My problem is that i need to load second dropdownlist on change of first dropdownlist how its possible.


i am pasting my code here.Please help me.Its very urgent.

VB.NET:
 Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

        Dim counter As Integer
        Label4.Visible = True
        Label5.Visible = True
        Label6.Visible = True
        Dim ddl As DropDownList
        Dim ddl2 As DropDownList
        Dim ddl3 As DropDownList

        For counter = 1 To TextBox1.Text Step 1

            ddl = New DropDownList()
            ddl.Width = 160
            ddl.ID = "DropDownListID" + (counter + 1).ToString()

            ddl2 = New DropDownList()
            ddl2.Width = 160
            ddl2.ID = "DropDownListID" + (counter + 1).ToString()

            ddl3 = New DropDownList()
            ddl3.Width = 160
            ddl3.ID = "DropDownListID" + (counter + 1).ToString()

                   Panel1.Controls.Add(ddl)
            Panel1.Controls.Add(New LiteralControl("<br><br>"))

        

            Panel2.Controls.Add(ddl2)
            Panel2.Controls.Add(New LiteralControl("<br><br>"))
           
            Panel3.Controls.Add(ddl3)
            Panel3.Controls.Add(New LiteralControl("<br><br>"))

            Dim cmd As New SqlCommand
            Dim dr As SqlDataReader
            Dim cmd1 As New SqlCommand
            Dim dr1 As SqlDataReader
            'Try
            ' If (Not IsPostBack = True) Then
            conn.ConnectionString = connString
            conn.Open()
            sql = "select distinct Main_Category from Category_Details ORDER BY Main_Category"
            cmd = New SqlCommand(sql, conn)
            dr = cmd.ExecuteReader()
            ddl.Items.Add("SELECT")
            Label7.Text = 1
            While (dr.Read())
                ddl.Items.Add(dr.GetString(0))
            End While
                      dr.Close()
            cmd.Dispose()



            'sql1 = "select distinct Sub_Category from Category_Details where Main_Category ='" + ddl.Text + "'"
               cmd1 = New SqlCommand(sql1, conn)
            dr1 = cmd1.ExecuteReader()
            ddl2.Items.Add("SELECT")

            While (dr1.Read())
                ddl2.Items.Add(dr1.GetString(0))
            End While
            dr1.Close()
            cmd1.Dispose()
            ' End If
            'Catch ex As Exception
            'End Try

            sql1 = "select distinct Products from Category_Details  where sub_Category ='" + ddl2.Text + "'"
            cmd1 = New SqlCommand(sql1, conn)
            dr1 = cmd1.ExecuteReader()
            ddl3.Items.Add("SELECT")

            While (dr1.Read())
                ddl3.Items.Add(dr1.GetString(0))
            End While
            dr1.Close()
            cmd1.Dispose()

            conn.Close()
        Next
    End Sub
 
Last edited by a moderator:
Back
Top