cfisher440
Well-known member
- Joined
- Oct 11, 2005
- Messages
- 73
- Programming Experience
- 1-3
I have two drop down boxes(ddlIssue and ddlSubIssue)
ddlIssue populates data from table named issues. Issues table contains columns named issueid, issue, and subidvid
ddlSubIssue populates data from table named subissues. subissues table contains columns named subissueid, subissue, and issuid
issueid is the primary key in issues table and foreign key in subissues table.
Based off whatever issue (value) is selected in ddlIssue, the appropriate subissue(s) (values) should show up in ddlSubIssue
This can be done easy enough like this:
That's the basics there for getting it done. That will work just fine.
BUT before ddlSubIssue is populated I want to verify that values in the subissues table exist.
In other words, if you select an issue from the ddlIssue (references the primary key of issues table) but there is no corresponding values in the issueid field of the subissues table to populate ddlSubIssue with, how would I first check to see if there are any issueid values in subissues table equal to the ddlissue's selectedvalue?? If there are no values, then I would like it to check another table.
That probably sounds very confusing.
I have seen a way of doing this in which you test if a row with the specified key value exists
The only problem there, is your testing the primary key value field of that table.
My case is very similar, but I am referencing the foreign value field. Referencing the foreign value field does mean there could be several ddlIssues.SelectedValue.ToStrings, as opposed to finding the one primary key. But as long as I can tell if there is just one of those foreign key values in the table, then I can flow.
Any help would be greatly appreciated.
ddlIssue populates data from table named issues. Issues table contains columns named issueid, issue, and subidvid
ddlSubIssue populates data from table named subissues. subissues table contains columns named subissueid, subissue, and issuid
issueid is the primary key in issues table and foreign key in subissues table.
Based off whatever issue (value) is selected in ddlIssue, the appropriate subissue(s) (values) should show up in ddlSubIssue
This can be done easy enough like this:
VB.NET:
1 'This is beneath windows form designer, before page load
2 Dim dsSubDivs As DataSet
3 Public dvSubDivs As DataView
4 Dim dsIssues As DataSet
5 Public dvIssues As DataView
6 Dim dsSubIssues As DataSet
7 Public dvSubIssues As DataView
8
9 Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
10 'Put user code to initialize the page here
11
12 dsSubIssues = GetSubIssue1orRes()
13
14 If Not IsPostBack Then
15 dsIssues = GetIssues()
16 Me.BindIssuesListBox()
17
18 End If
19
20 End Sub
21
22 Private Sub BindIssueDropDownList()
23 ddlIssues.DataSource = dvIssuescat
24 'ddlSubDivision.DataMember = "subdiv"
25 ddlIssues.DataTextField = "issuename"
26 ddlIssues.DataValueField = "issueid"
27 ddlIssues.DataBind()
28 End Sub
29
30 Private Sub BindSubIssueDropDownList()
31 Dim dvSubIssues As New DataView(dsSubIssues.Tables("subIssue1"))
32
33 dvSubIssues.RowFilter _
34 = "issueid='" & ddlIssues.SelectedValue & "'"
35 ddlSubIssue.DataSource = dvSubIssues
36 'ddlSubDivision.DataMember = "subdiv"
37 ddlSubIssue.DataTextField = "subissue"
38 ddlSubIssue.DataValueField = "subissueid"
39 ddlSubIssue.DataBind()
40 End Sub
41
42 Function GetIssues() As DataSet
43 Dim dsIssues As New DataSet
44 If HttpContext.Current.Cache("dsIssues") Is Nothing Then
45 Dim sSelect As String = "SELECT issueid, issueName, subdivid " _
46 & "FROM issues ORDER BY issueName"
47 Dim daIssues As New OleDb.OleDbDataAdapter(sSelect, OleDbConnection1)
48 daIssues.MissingSchemaAction = MissingSchemaAction.AddWithKey
49 daIssues.Fill(dsIssues, "issues")
50 HttpContext.Current.Cache("dsIssues") = dsIssues
51 Else
52 dsIssues = HttpContext.Current.Cache("dsIssues")
53 End If
54 Return dsIssues
55 End Function
56
57 Function GetSubIssue1orRes() As DataSet
58 Dim dsSubIssues As New DataSet
59 If HttpContext.Current.Cache("dsSubIssues") Is Nothing Then
60 Dim sSelect As String = "SELECT subissueID, subissue, issueid " _
61 & "FROM subIssue1 ORDER BY subissue"
62 Dim daSubIssues As New OleDb.OleDbDataAdapter(sSelect, OleDbConnection1)
63 daSubIssues.MissingSchemaAction = MissingSchemaAction.AddWithKey
64 daSubIssues.FillSchema(dsSubIssues, SchemaType.Mapped)
65 'dsSubIssues.Tables("subIssue1").PrimaryKey = New DataColumn
66 daSubIssues.Fill(dsSubIssues, "subIssue1")
67 HttpContext.Current.Cache("dsSubIssues") = dsSubIssues
68 Else
69 dsSubIssues = HttpContext.Current.Cache("dsSubIssues")
70 End If
71 Return dsSubIssues
72 End Function
73
74 Private Sub ddlIssues_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddlIssues.SelectedIndexChanged
75 Me.BindSubIssueDropDownList()
76 End Sub
BUT before ddlSubIssue is populated I want to verify that values in the subissues table exist.
In other words, if you select an issue from the ddlIssue (references the primary key of issues table) but there is no corresponding values in the issueid field of the subissues table to populate ddlSubIssue with, how would I first check to see if there are any issueid values in subissues table equal to the ddlissue's selectedvalue?? If there are no values, then I would like it to check another table.
That probably sounds very confusing.
I have seen a way of doing this in which you test if a row with the specified key value exists
VB.NET:
If dsSubIssues.Tables("subissue").Rows.Contains(ddlIssues.SelectedValue.ToString) Then ...
My case is very similar, but I am referencing the foreign value field. Referencing the foreign value field does mean there could be several ddlIssues.SelectedValue.ToStrings, as opposed to finding the one primary key. But as long as I can tell if there is just one of those foreign key values in the table, then I can flow.
Any help would be greatly appreciated.
Last edited by a moderator: