two relation Drop down list
-
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
-
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
write the code for binding the second drop down of titles in Selected indexchanged property of first drop down.
-
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
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 ist_linkChapter.link_chapterid = t_linkTitle.link_chapterid
Try out this Code Set ddlLessonAutoPostBack
property to True. Which will fireddlLesson_SelectedIndexChanged
When ever user select a new TitlePrivate 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 SubPrivate 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
-
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 ist_linkChapter.link_chapterid = t_linkTitle.link_chapterid
Try out this Code Set ddlLessonAutoPostBack
property to True. Which will fireddlLesson_SelectedIndexChanged
When ever user select a new TitlePrivate 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 SubPrivate 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
Oh thanks very much. It work.
-
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 ist_linkChapter.link_chapterid = t_linkTitle.link_chapterid
Try out this Code Set ddlLessonAutoPostBack
property to True. Which will fireddlLesson_SelectedIndexChanged
When ever user select a new TitlePrivate 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 SubPrivate 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
Oh thanks guys..I got it.;)
-
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
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?