Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. two relation Drop down list

two relation Drop down list

Scheduled Pinned Locked Moved ASP.NET
databasesysadminhelp
6 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    LovelyHelp
    wrote on last edited by
    #1

    I will like to create 2 dropdown list which have relationship connected. The first dropdownlist will contain chapter(Parent ddl) and the second dropdown list will contain my title (children) When i select on my Chapter in my first drop down list it will show only the title belong to the chapter that I have selected in second drop down list. But now the problem I found is, the title drop down list always show the the title item which also not belong to the chapter that i have selected. My code is as below ----------------------------------------------------------------------------:confused: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim myConnection As SqlConnection Dim cmdSelect As SqlCommand Dim dr As SqlDataReader myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc") myConnection.Open() 'call the Chapter item to drop down list cmdSelect = New SqlCommand("select * from t_linkChapter", myConnection) dr = cmdSelect.ExecuteReader() ddlLesson.DataSource = dr ddlLesson.DataTextField = "link_chapter" ddlLesson.DataValueField = "link_chapterid" ddlLesson.DataBind() dr.Close() If IsPostBack Then Dim cmdSelect2 As SqlCommand Dim dr2 As SqlDataReader cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader() ddlTitle.DataSource = dr2 ddlTitle.DataTextField = "link_title" ddlTitle.DataValueField = "link_titleid" ddlTitle.DataBind() dr2.Close() End If myConnection.Close() End Sub

    G A L 3 Replies Last reply
    0
    • L LovelyHelp

      I will like to create 2 dropdown list which have relationship connected. The first dropdownlist will contain chapter(Parent ddl) and the second dropdown list will contain my title (children) When i select on my Chapter in my first drop down list it will show only the title belong to the chapter that I have selected in second drop down list. But now the problem I found is, the title drop down list always show the the title item which also not belong to the chapter that i have selected. My code is as below ----------------------------------------------------------------------------:confused: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim myConnection As SqlConnection Dim cmdSelect As SqlCommand Dim dr As SqlDataReader myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc") myConnection.Open() 'call the Chapter item to drop down list cmdSelect = New SqlCommand("select * from t_linkChapter", myConnection) dr = cmdSelect.ExecuteReader() ddlLesson.DataSource = dr ddlLesson.DataTextField = "link_chapter" ddlLesson.DataValueField = "link_chapterid" ddlLesson.DataBind() dr.Close() If IsPostBack Then Dim cmdSelect2 As SqlCommand Dim dr2 As SqlDataReader cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader() ddlTitle.DataSource = dr2 ddlTitle.DataTextField = "link_title" ddlTitle.DataValueField = "link_titleid" ddlTitle.DataBind() dr2.Close() End If myConnection.Close() End Sub

      G Offline
      G Offline
      goyal manish
      wrote on last edited by
      #2

      write the code for binding the second drop down of titles in Selected indexchanged property of first drop down.

      1 Reply Last reply
      0
      • L LovelyHelp

        I will like to create 2 dropdown list which have relationship connected. The first dropdownlist will contain chapter(Parent ddl) and the second dropdown list will contain my title (children) When i select on my Chapter in my first drop down list it will show only the title belong to the chapter that I have selected in second drop down list. But now the problem I found is, the title drop down list always show the the title item which also not belong to the chapter that i have selected. My code is as below ----------------------------------------------------------------------------:confused: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim myConnection As SqlConnection Dim cmdSelect As SqlCommand Dim dr As SqlDataReader myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc") myConnection.Open() 'call the Chapter item to drop down list cmdSelect = New SqlCommand("select * from t_linkChapter", myConnection) dr = cmdSelect.ExecuteReader() ddlLesson.DataSource = dr ddlLesson.DataTextField = "link_chapter" ddlLesson.DataValueField = "link_chapterid" ddlLesson.DataBind() dr.Close() If IsPostBack Then Dim cmdSelect2 As SqlCommand Dim dr2 As SqlDataReader cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader() ddlTitle.DataSource = dr2 ddlTitle.DataTextField = "link_title" ddlTitle.DataValueField = "link_titleid" ddlTitle.DataBind() dr2.Close() End If myConnection.Close() End Sub

        A Offline
        A Offline
        Anish Gopi
        wrote on last edited by
        #3

        LovelyHelp wrote:

        cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader()

        you are joining t_linkChapter.link_chapterid = t_linkTitle.link_titleid but what you need is t_linkChapter.link_chapterid = t_linkTitle.link_chapterid Try out this Code Set ddlLesson AutoPostBack property to True. Which will fire ddlLesson_SelectedIndexChanged When ever user select a new Title

        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        If Not IsPostBack Then
        LoadChapters()
        LoadTitle()
        End If
        End Sub

        Private Sub ddlLesson\_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
            'Load Title when ever a new chapter is selected
            LoadTitle()
        End Sub
        
        Private Sub LoadChapters()
        
            Dim myConnection As SqlConnection
            Dim cmdSelect As SqlCommand
            Dim dr As SqlDataReader
        
            myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
            myConnection.Open()
        
            'call the Chapter item to drop down list
            cmdSelect = New SqlCommand("select \* from t\_linkChapter", myConnection)
            dr = cmdSelect.ExecuteReader()
        
            ddlLesson.DataSource = dr
            ddlLesson.DataTextField = "link\_chapter"
            ddlLesson.DataValueField = "link\_chapterid"
            ddlLesson.DataBind()
            dr.Close()
            myConnection.Close()
        End Sub
        
        
        Private Sub LoadTitle()
        
        
            Dim myConnection As SqlConnection
            myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
            myConnection.Open()
        
            Dim cmdSelect2 As SqlCommand
            Dim dr2 As SqlDataReader
            cmdSelect2 = New SqlCommand("SELECT link\_titleid, link\_title FROM t\_linkTitle Where t\_linkTitle.link\_chapterid = " & ddlLesson.SelectedValue, myConnection)
            dr2 = cmdSelect2.ExecuteReader()
        
            ddlTitle.DataSource = dr2
            ddlTitle.DataTextField = "link\_title"
            ddlTitle.DataValueField = "link\_titleid"
            ddlTitle.DataBind()
            dr2.Close()
            myConnection.Close()
        
        End Sub
        
        L 2 Replies Last reply
        0
        • A Anish Gopi

          LovelyHelp wrote:

          cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader()

          you are joining t_linkChapter.link_chapterid = t_linkTitle.link_titleid but what you need is t_linkChapter.link_chapterid = t_linkTitle.link_chapterid Try out this Code Set ddlLesson AutoPostBack property to True. Which will fire ddlLesson_SelectedIndexChanged When ever user select a new Title

          Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          If Not IsPostBack Then
          LoadChapters()
          LoadTitle()
          End If
          End Sub

          Private Sub ddlLesson\_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
              'Load Title when ever a new chapter is selected
              LoadTitle()
          End Sub
          
          Private Sub LoadChapters()
          
              Dim myConnection As SqlConnection
              Dim cmdSelect As SqlCommand
              Dim dr As SqlDataReader
          
              myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
              myConnection.Open()
          
              'call the Chapter item to drop down list
              cmdSelect = New SqlCommand("select \* from t\_linkChapter", myConnection)
              dr = cmdSelect.ExecuteReader()
          
              ddlLesson.DataSource = dr
              ddlLesson.DataTextField = "link\_chapter"
              ddlLesson.DataValueField = "link\_chapterid"
              ddlLesson.DataBind()
              dr.Close()
              myConnection.Close()
          End Sub
          
          
          Private Sub LoadTitle()
          
          
              Dim myConnection As SqlConnection
              myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
              myConnection.Open()
          
              Dim cmdSelect2 As SqlCommand
              Dim dr2 As SqlDataReader
              cmdSelect2 = New SqlCommand("SELECT link\_titleid, link\_title FROM t\_linkTitle Where t\_linkTitle.link\_chapterid = " & ddlLesson.SelectedValue, myConnection)
              dr2 = cmdSelect2.ExecuteReader()
          
              ddlTitle.DataSource = dr2
              ddlTitle.DataTextField = "link\_title"
              ddlTitle.DataValueField = "link\_titleid"
              ddlTitle.DataBind()
              dr2.Close()
              myConnection.Close()
          
          End Sub
          
          L Offline
          L Offline
          LovelyHelp
          wrote on last edited by
          #4

          Oh thanks very much. It work.

          1 Reply Last reply
          0
          • A Anish Gopi

            LovelyHelp wrote:

            cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader()

            you are joining t_linkChapter.link_chapterid = t_linkTitle.link_titleid but what you need is t_linkChapter.link_chapterid = t_linkTitle.link_chapterid Try out this Code Set ddlLesson AutoPostBack property to True. Which will fire ddlLesson_SelectedIndexChanged When ever user select a new Title

            Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Not IsPostBack Then
            LoadChapters()
            LoadTitle()
            End If
            End Sub

            Private Sub ddlLesson\_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
                'Load Title when ever a new chapter is selected
                LoadTitle()
            End Sub
            
            Private Sub LoadChapters()
            
                Dim myConnection As SqlConnection
                Dim cmdSelect As SqlCommand
                Dim dr As SqlDataReader
            
                myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
                myConnection.Open()
            
                'call the Chapter item to drop down list
                cmdSelect = New SqlCommand("select \* from t\_linkChapter", myConnection)
                dr = cmdSelect.ExecuteReader()
            
                ddlLesson.DataSource = dr
                ddlLesson.DataTextField = "link\_chapter"
                ddlLesson.DataValueField = "link\_chapterid"
                ddlLesson.DataBind()
                dr.Close()
                myConnection.Close()
            End Sub
            
            
            Private Sub LoadTitle()
            
            
                Dim myConnection As SqlConnection
                myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc")
                myConnection.Open()
            
                Dim cmdSelect2 As SqlCommand
                Dim dr2 As SqlDataReader
                cmdSelect2 = New SqlCommand("SELECT link\_titleid, link\_title FROM t\_linkTitle Where t\_linkTitle.link\_chapterid = " & ddlLesson.SelectedValue, myConnection)
                dr2 = cmdSelect2.ExecuteReader()
            
                ddlTitle.DataSource = dr2
                ddlTitle.DataTextField = "link\_title"
                ddlTitle.DataValueField = "link\_titleid"
                ddlTitle.DataBind()
                dr2.Close()
                myConnection.Close()
            
            End Sub
            
            L Offline
            L Offline
            LovelyHelp
            wrote on last edited by
            #5

            Oh thanks guys..I got it.;)

            1 Reply Last reply
            0
            • L LovelyHelp

              I will like to create 2 dropdown list which have relationship connected. The first dropdownlist will contain chapter(Parent ddl) and the second dropdown list will contain my title (children) When i select on my Chapter in my first drop down list it will show only the title belong to the chapter that I have selected in second drop down list. But now the problem I found is, the title drop down list always show the the title item which also not belong to the chapter that i have selected. My code is as below ----------------------------------------------------------------------------:confused: Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load Dim myConnection As SqlConnection Dim cmdSelect As SqlCommand Dim dr As SqlDataReader myConnection = New SqlConnection("server=localhost;UID=;pwd=;database=abc") myConnection.Open() 'call the Chapter item to drop down list cmdSelect = New SqlCommand("select * from t_linkChapter", myConnection) dr = cmdSelect.ExecuteReader() ddlLesson.DataSource = dr ddlLesson.DataTextField = "link_chapter" ddlLesson.DataValueField = "link_chapterid" ddlLesson.DataBind() dr.Close() If IsPostBack Then Dim cmdSelect2 As SqlCommand Dim dr2 As SqlDataReader cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title, t_linkTitle.link_chapterid, t_linkChapter.link_chapterid FROM t_linkTitle LEFT JOIN t_linkChapter ON t_linkChapter.link_chapterid = t_linkTitle.link_titleid", myConnection) dr2 = cmdSelect2.ExecuteReader() ddlTitle.DataSource = dr2 ddlTitle.DataTextField = "link_title" ddlTitle.DataValueField = "link_titleid" ddlTitle.DataBind() dr2.Close() End If myConnection.Close() End Sub

              L Offline
              L Offline
              LovelyHelp
              wrote on last edited by
              #6

              I have my code here is when button 'update' is click, it will run the script as below. Protected Sub DoUpdate(ByVal sender As Object, ByVal e As System.EventArgs) Handles bttnUpUpdate.Click 'set the panel of selection function to display pTitle.Visible = True pLesson.Visible = True pAdd.Visible = True pUpdate.Visible = False pAddChapter.Visible = False Dim myconnection As SqlConnection Dim mycommand As SqlCommand Dim selectedID As String = ddlTitle.SelectedItem.Value myconnection = New SqlConnection("Server=localhost;UID=sa;pwd=;database=u") myconnection.Open() mycommand = New SqlCommand("Update t_linkTitle SET link_title=@txtUpTitle, link_url=@txtUpLink WHERE link_titleid=" + selectedID, myconnection) mycommand.Parameters.Add("@txtUpTitle", SqlDbType.VarChar, 100).Value = txtUpTitle.Text mycommand.Parameters.Add("@txtUpLink", SqlDbType.VarChar, 100).Value = txtUpLink.Text mycommand.ExecuteNonQuery() myconnection.Close() LoadTitle() End Sub Private Sub LoadTitle() Dim myConnection As SqlConnection myConnection = New SqlConnection("server=localhost;UID=sa;pwd=119478;database=userLogin") myConnection.Open() Dim cmdSelect2 As SqlCommand Dim dr2 As SqlDataReader cmdSelect2 = New SqlCommand("SELECT link_titleid, link_title FROM t_linkTitle Where t_linkTitle.link_chapterid = " & ddlLesson.SelectedValue, myConnection) dr2 = cmdSelect2.ExecuteReader() ddlTitle.DataSource = dr2 ddlTitle.DataTextField = "link_title" ddlTitle.DataValueField = "link_titleid" ddlTitle.DataBind() dr2.Close() myConnection.Close() End Sub But when I run my code, there is an runtime error saying "Object reference not set to an instance of an object." Source Error: Line 245: sFile = txtUpload.PostedFile.FileName Line 246: sFile2 = txtUpload2.PostedFile.FileName Line 247: sFile3 = txtUpload3.PostedFile.FileName Which the error are not inside the 2 sub code that I have posted here. sFile = txtUpload.PostedFile.FileName sFile2 = txtUpload2.PostedFile.FileName sFile3 = txtUpload3.PostedFile.FileName This code appear when I add new title to database but it is under a same application. what can it be?

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups