Advertisement

05.09.2008 at 02:15PM PDT, ID: 23390848
[x]
Attachment Details

5 dynamic dropdowns

Asked by ratkinso666 in Visual Studio .NET 2005, Microsoft Visual Basic.Net

Tags: microsoft, Visual Studio, 2005, vb

Hi all, I am building a page with 5 dropdowns that are populated based on the previous dropdown (drilldown style) they then feed to a gridview.  I am having trouble getting them to work correctly.  I have 5 dropdowns, but necessarily all of them will be used.  The first dropdown is of course completely populated, but then from that I need to see the gridview that shows me data from that first dropdown, PLUS the next dropdown, if there is another dropdown below this one, then when I select THAT dropdown I need the gridview to change according to what I picked in the dropdown, plus check if there is another level below this dropdown, all the way to a MAX of 5 dropdowns.  This is the code I have thus far:

The problem is that when I select my dropdown it is not properly selecting my gridview AND when I make a selection on the dropdown and there is only one selection, it will not allow me to select that option and move on to the dropdowns below that one.

ANY questions please ask, I know it sounds confusing...
This is in Visual Studio 2005 VB
Thanks,
RandyStart Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
148:
149:
150:
151:
152:
153:
154:
155:
156:
157:
158:
159:
160:
161:
162:
163:
164:
165:
166:
167:
168:
169:
170:
171:
172:
173:
174:
175:
176:
177:
178:
179:
180:
181:
182:
183:
184:
185:
186:
187:
188:
189:
190:
191:
192:
193:
194:
195:
196:
197:
198:
199:
200:
201:
202:
203:
204:
205:
206:
207:
208:
209:
210:
211:
212:
213:
214:
215:
216:
217:
218:
219:
220:
221:
222:
223:
224:
225:
226:
227:
228:
229:
230:
231:
232:
233:
234:
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
        <ContentTemplate>
            <br />
       
        <asp:Panel runat="server" ID="DropDown1Form">     
            <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1"
                DataTextField="Description" DataValueField="Group_ID">
            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT DISTINCT JSA_Groups.[Description], JSA_Groups.[Group_ID] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID = JSA_Groups_1.Parent ORDER BY JSA_Groups.[Description]">
            </asp:SqlDataSource>
        </asp:Panel>    
            
            
        <asp:Panel runat="server" ID="DropDown2Form" Visible="False">
              <asp:DropDownList ID="DropDownList2" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource3"
                DataTextField="Description" DataValueField="Group_ID">
             </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource3" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID) ORDER BY JSA_Groups.[Description]">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="Group_ID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </asp:Panel>            
            
            
        <asp:Panel runat="server" ID="DropDown3Form" Visible="False">    
            <asp:DropDownList ID="DropDownList3" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource4"
                DataTextField="Description" DataValueField="Group_ID">
            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID) ORDER BY JSA_Groups.[Description]">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList2" Name="Group_ID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </asp:Panel> 
        
            
        <asp:Panel runat="server" ID="DropDown4Form" Visible="False">    
            <asp:DropDownList ID="DropDownList4" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource5"
                DataTextField="Description" DataValueField="Group_ID">
            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource5" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID) ORDER BY JSA_Groups.[Description]">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList3" Name="Group_ID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </asp:Panel> 
        
            
        <asp:Panel runat="server" ID="DropDown5Form" Visible="False">        
            <asp:DropDownList ID="DropDownList5" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource6"
                DataTextField="Description" DataValueField="Group_ID">
            </asp:DropDownList><asp:SqlDataSource ID="SqlDataSource6" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID) ORDER BY JSA_Groups.[Description]">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList4" Name="Group_ID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </asp:Panel>     
            
            
            <br />
            <br />
            <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True"
                AutoGenerateColumns="False" CellPadding="4" DataSourceID="SqlDataSource2" ForeColor="#333333"
                GridLines="Both" PageSize="20">
                <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                <Columns>
                    <asp:TemplateField HeaderText="Description" SortExpression="File_Description">
                        <EditItemTemplate>
                            <asp:TextBox ID="TextBox1" runat="server" Text='<%# Bind("File_Description") %>'></asp:TextBox>
                        </EditItemTemplate>
                        <ItemTemplate>
                            &nbsp;<asp:HyperLink ID="HyperLink1" runat="server" Height="20px" NavigateUrl='<%# Bind("File_Name") %>'
                                Target="_new" Text='<%# Bind("File_Description") %>' Width="600px"></asp:HyperLink>
                        </ItemTemplate>
                    </asp:TemplateField>
                </Columns>
                <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                <AlternatingRowStyle BackColor="White" />
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:IntranetAppsConnectionString %>"
                SelectCommand="SELECT DISTINCT [File_Description], [File_Name] FROM [JSA_FileNames] WHERE ([Group_ID] = @Group_ID) ORDER BY [File_Description]" OnSelecting="SqlDataSource2_Selecting">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" Name="Group_ID" PropertyName="SelectedValue"
                        Type="Int32" />
                </SelectParameters>
            </asp:SqlDataSource>
        </ContentTemplate>
    </asp:UpdatePanel>
 
 
 
 
 
 
 
 
 
Code-behind:
 
Imports System.Data.SqlClient, system.data
Partial Class JSA
    Inherits System.Web.UI.Page
 
    Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
        Dim test As Boolean = False
        Try
            Dim queryString As String = "SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID)"
            Dim connection As New SqlClient.SqlConnection("Data Source=data")
            Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand(queryString, connection)
            command.Parameters.AddWithValue("@Group_ID", DropDownList1.SelectedValue)
            Dim reader As SqlClient.SqlDataReader
            command.Connection.Open()
            reader = command.ExecuteReader
            reader.Read()
            If reader.HasRows Then
                test = True
            End If
            command.Connection.Close()
        Catch ex As SystemException
            Response.Write(ex.ToString)
        End Try
        If test = True Then
            DropDown2Form.Visible = True
            DropDown3Form.Visible = False
            DropDown4Form.Visible = False
            DropDown5Form.Visible = False
        Else
            DropDown2Form.Visible = False
            DropDown3Form.Visible = False
            DropDown4Form.Visible = False
            DropDown5Form.Visible = False
        End If
    End Sub
 
    Protected Sub DropDownList2_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList2.SelectedIndexChanged
        Dim test As Boolean = False
        Try
            Dim queryString As String = "SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID)"
            Dim connection As New SqlClient.SqlConnection("Data Source=data")
            Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand(queryString, connection)
            command.Parameters.AddWithValue("@Group_ID", DropDownList2.SelectedValue)
            Dim reader As SqlClient.SqlDataReader
            command.Connection.Open()
            reader = command.ExecuteReader
            reader.Read()
            If reader.HasRows Then
                test = True
            End If
            command.Connection.Close()
        Catch ex As SystemException
            Response.Write(ex.ToString)
        End Try
        If test = True Then
            DropDown3Form.Visible = True
            DropDown4Form.Visible = False
            DropDown5Form.Visible = False
        Else
            DropDown3Form.Visible = False
            DropDown4Form.Visible = False
            DropDown5Form.Visible = False
        End If
 
    End Sub
 
    Protected Sub DropDownList3_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList3.SelectedIndexChanged
        Dim test As Boolean = False
        Try
            Dim queryString As String = "SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN  JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID)"
            Dim connection As New SqlClient.SqlConnection("Data Source=data")
            Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand(queryString, connection)
            command.Parameters.AddWithValue("@Group_ID", DropDownList3.SelectedValue)
            Dim reader As SqlClient.SqlDataReader
            command.Connection.Open()
            reader = command.ExecuteReader
            reader.Read()
            If reader.HasRows Then
                test = True
            End If
            command.Connection.Close()
        Catch ex As SystemException
            Response.Write(ex.ToString)
        End Try
        If test = True Then
            DropDown4Form.Visible = True
            DropDown5Form.Visible = False
        Else
            DropDown4Form.Visible = False
            DropDown5Form.Visible = False
        End If
    End Sub
 
    Protected Sub DropDownList4_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList4.SelectedIndexChanged
        DropDown5Form.Visible = True
    End Sub
 
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        If Page.IsPostBack Then
 
        End If
 
    End Sub
 
    Protected Sub SqlDataSource2_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs)
        If Not IsPostBack Then
            If DropDownList2.SelectedValue = "" Then
                e.Command.Parameters("@Group_ID").Value = DropDownList1.SelectedValue
            Else
                If DropDownList3.SelectedValue = "" Then
                    e.Command.Parameters("@Group_ID").Value = DropDownList2.SelectedValue
                Else
                    If DropDownList4.SelectedValue = "" Then
                        e.Command.Parameters("@Group_ID").Value = DropDownList3.SelectedValue
                    Else
                        If DropDownList5.SelectedValue = "" Then
                            e.Command.Parameters("@Group_ID").Value = DropDownList4.SelectedValue
                        Else
                            e.Command.Parameters("@Group_ID").Value = DropDownList5.SelectedValue
                        End If
                    End If
                End If
            End If
        End If
    End Sub
End Class
[+][-]05.09.2008 at 11:14PM PDT, ID: 21538018

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]05.10.2008 at 05:53AM PDT, ID: 21538860

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: Visual Studio .NET 2005, Microsoft Visual Basic.Net
Tags: microsoft, Visual Studio, 2005, vb
Sign Up Now!
Solution Provided By: ratkinso666
Participating Experts: 1
Solution Grade: A
 
 
[+][-]05.14.2008 at 06:19AM PDT, ID: 21563799

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
Microsoft
  • Internet Protocols
  • Applications
  • Development
  • OS
  • Hardware
  • Windows Security
Apple
  • Operating Systems
  • Hardware
  • Programming
  • Networking
  • Software
Internet
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Spy / Ad Blockers
  • Web Browsers
  • New Net Users
  • Web Development
  • Chat / IM
  • Anti Spam
  • Web Servers
  • Anti-Virus
  • Email Clients
Gamers
  • Tips
  • Online / MMORPG
  • Puzzle
  • Emulators
  • Action / Adventure
  • Role Playing
  • Consoles
  • Game Programming
  • Strategy
  • Sports
  • Misc
  • Computer Games
Digital Living
  • Hardware
  • Automotive
  • New Net Users
  • New Users
  • Software
  • Digital Music
  • Gaming World
  • Home Security
  • Apple
  • Networking Hardware
Virus & Spyware
  • Vulnerabilities
  • IDS
  • Encryption
  • Anti-Virus
  • Operating Systems Security
  • Software Firewalls
  • WebApplications
  • Cell Phones
  • Operating Systems
  • Internet
  • Hardware Firewalls
Hardware
  • Displays / Monitors
  • Handhelds / PDAs
  • Components
  • Peripherals
  • Laptops/Notebooks
  • Servers
  • Misc
  • Apple
  • Embedded Hardware
  • Networking Hardware
  • Storage
  • Desktops
  • New Users
Software
  • System Utilities
  • Industry Specific
  • Network Management
  • Photos / Graphics
  • Page Layout
  • VMware
  • Misc
  • Web Development
  • OS
  • CYGWIN
  • Voice Recognition
  • Virtualization
  • Message Queue
  • Quality Assurance
  • Security
  • Firewalls
  • MultiMedia Applications
  • Development
  • Database
  • Office / Productivity
  • Business Management
  • OS/2 Apps
  • Server Software
  • Internet / Email
ITPro
  • OS
  • Storage
  • Encryption
  • Operating Systems Security
  • Apple Hardware
  • Laptops & Notebooks
  • Servers
  • Networking Hardware
  • Peripherals
  • Devices
  • Displays / Monitors
  • WebTrends / Stats
  • Search Engines
  • Firewalls
  • Web Computing
  • WebApplications
  • IDS
  • Vulnerabilities
  • Email Clients
  • File Sharing
  • Spy / Ad Blockers
  • Web Browsers
  • Web Servers
  • Networking
  • Anti-Virus
  • Consulting
  • Chat / IM
  • Anti Spam
Developer
  • Web Servers
  • Web Browsers
  • Game Programming
  • Dev Tools
  • Industry Specific
  • Office / Productivity
  • Database
  • CYGWIN
  • Web Development
  • Search Engines
  • File Sharing
  • WebTrends / Stats
  • Programming
  • Content Management
  • Application Servers
  • Protocols
Storage
  • Removable Backup Media
  • Storage Technology
  • Servers
  • Grid
  • Remote Access
  • Backup / Restore
  • Misc
  • Hard Drives
OS
  • Miscellaneous
  • Security
  • Development
  • Linux
  • VMware
  • MainFrame OS
  • Unix
  • Apple
  • OS / 2
  • AS / 400
  • BeOS
  • Microsoft
  • VMS / OpenVMS
Database
  • Oracle
  • Miscellaneous
  • MySQL
  • Software
  • Sybase
  • Contact Management
  • PostgreSQL
  • Data Manipulation
  • Clarion
  • InterSystems Cache
  • Siebel
  • MUMPS
  • OLAP
  • SQLBase
  • SAS
  • GIS & GPS
  • 4GL
  • Berkeley DB
  • DB2
  • Informix
  • Interbase / Firebird
  • FoxPro
  • Reporting
  • LDAP
  • Filemaker Pro
  • MS SQL Server
  • dBase
  • MS Access
Security
  • Misc
  • Web Browsers
  • Software Firewalls
  • Operating Systems Security
  • File Sharing
  • Spy / Ad Blockers
  • Vulnerabilities
  • WebApplications
  • IDS
  • Anti-Virus
  • Encryption
  • Anti Spam
  • Email Clients
  • VPN
  • Chat / IM
Programming
  • Editors IDEs
  • Installation
  • Handhelds / PDAs
  • Multimedia Programming
  • System / Kernel
  • Automation
  • Algorithms
  • Game
  • Signal Processing
  • Project Management
  • Open Source
  • Database
  • Misc
  • Languages
  • Processor Platforms
  • Theory
Web Development
  • Scripting
  • Blogs
  • Web Servers
  • Software
  • Search Engines
  • Web Graphics
  • Web Services
  • Images
  • Internet Marketing
  • Images and Photos
  • Components
  • Document Imaging
  • Web Languages/Standards
  • Illustration
  • WebApplications
  • Fonts
  • WebTrends / Stats
  • Authoring
  • Digital Camera Software
  • Miscellaneous
Networking
  • Protocols
  • Apple Networking
  • Network Management
  • Message Queue
  • Application Servers
  • Content Management
  • File Servers
  • Email Servers
  • Misc
  • Java Editors & IDEs
  • Wireless
  • Networking Hardware
  • Backup / Restore
  • System Utilities
  • ISPs & Hosting
  • Web Servers
  • Storage Technology
  • Removable Backup Media
  • Servers
  • Web Computing
  • Broadband
  • Grid
  • OS / 2
  • Novell Netware
  • Unix Networking
  • Windows Networking
  • Security
  • Telecommunications
  • Operating Systems
  • Linux Networking
Other
  • Lounge
  • Business Travel
  • Community Support
  • New Net Users
  • Philosophy / Religion
  • Math / Science
  • Miscellaneous
  • URLs
  • Expert Lounge
  • Politics
  • Puzzles / Riddles
  • Automotive
Community Support
  • Suggestions
  • New to EE
  • New Topics
  • CleanUp
  • Announcements
  • General
  • Feedback
  • Input
  • EE Bugs
 
05.09.2008 at 11:14PM PDT, ID: 21538018
I reviewed the code you posted.  It looks like you've painted youself into a corner- no way out without repainting. I wish I could give you a meaningful answer, however it appears that you cannot get there from here.

There is plenty of designer-generated source in your sample . As you have discovered, designer tools/features seem easy, but they have many limitations that can be difficult to overcome. All that stuff is just making it harder on you. It is far easier to do it all in code with only the basic designer tools.

Perhaps you should ask how to do the necessary tasks in code.  Building datasources in classes. Building and binding GridViews in code. Binding GridViews to a set of drilldowns in code. A few questions like that should go a long way to help you reach your goal.
 
Assisted Solution
 
05.10.2008 at 05:53AM PDT, ID: 21538860
Hi funwithdotnet, if you could help me out on getting started with that, that would be great, as I am looking for a solution to the problem and if that is the direction I need to go then a start to that end would be considered an answer to at least this part of the problem.

Thanks,
Randy
Accepted Solution
 
05.14.2008 at 06:19AM PDT, ID: 21563799
Hi all, I still seem to be having problems with this, here is what I have for one of the drop-downs, I have not made any changes to the others yet, until I get one working correctly, I am trying to do it more the way funwithdotnet said and create the drop-down programatically:

Thanks for your help,

Randy
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
<asp:DropDownList ID="DropDownList1" runat="server" DataTextField="Description" DataValueField="Group_ID"
DataSource='<%# PopulateList() %>' AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
</asp:DropDownList>
 
cod-behind: 
 
Protected Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Dim test As Boolean = False
Try
 
'I did this just to determine if I should show the next dropdown or not...  each dropdown is in its own form
Dim queryString As String = "SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent WHERE (JSA_Groups.[Parent] = @Group_ID)" 
 
Dim connection As New SqlClient.SqlConnection("Data Source=HCISSQL2;Initial Catalog=...;User ID=apps;Password=...")
Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand(queryString, connection)
command.Parameters.AddWithValue("@Group_ID", DropDownList1.SelectedValue)
Dim reader As SqlClient.SqlDataReader
command.Connection.Open()
reader = command.ExecuteReader
reader.Read()
If reader.HasRows Then
     test = True
     DropDownList2.DataBind()
End If
command.Connection.Close()
Catch ex As SystemException
Response.Write(ex.ToString)
End Try
 
If test = True Then
DropDown2Form.Visible = True
DropDown3Form.Visible = False
DropDown4Form.Visible = False
DropDown5Form.Visible = False
Else
 
DropDown2Form.Visible = False
DropDown3Form.Visible = False
DropDown4Form.Visible = False
DropDown5Form.Visible = False
End If
End Sub
 
Protected Function PopulateList() As DataTable  
Dim queryString As String = "SELECT JSA_Groups.[Group_ID], JSA_Groups.[Description] FROM [JSA_Groups] INNER JOIN JSA_Groups JSA_Groups_1 ON JSA_Groups.Group_ID = JSA_Groups_1.Group_ID AND JSA_Groups.Group_ID <> JSA_Groups_1.Parent"
 
Dim connection As New SqlClient.SqlConnection("Data Source=HCISSQL2;Initial Catalog=...;User ID=apps;Password=...")
Dim command As SqlClient.SqlCommand = New SqlClient.SqlCommand(queryString, connection)
Dim dr As SqlDataReader = command.ExecuteReader(CommandBehavior.CloseConnection)
Dim _dtList As New DataTable()
_dtList.Load(dr)
_dtList.Columns.Add("Group_ID")
_dtList.Columns.Add("Description")
_dtList.Rows.Add(0, "-- Select a value --")
 
 
'Use for each loop and add it to the datatable
For Each row As DataRow In (_dtList.Rows)
DropDownList1.DataValueField = ("Group_ID")
DropDownList1.DataTextField = ("Description")
Next
 
DropDownList1.DataBind()
Return _dtList
 
End Function
 
I am currently getting this error:  I set a breakpoint at the function populateList, and get this error before that happens....
 
Input string was not in a correct format.
 
[FormatException: Input string was not in a correct format.]
   System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal) +2755599
   System.Number.ParseInt32(String s, NumberStyles style, NumberFormatInfo info) +112
   System.String.System.IConvertible.ToInt32(IFormatProvider provider) +43
   System.Convert.ChangeType(Object value, Type conversionType, IFormatProvider provider) +217
   System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType) +896
 
[FormatException: Failed to convert parameter value from a String to a Int32.]
   System.Data.SqlClient.SqlParameter.CoerceValue(Object value, MetaType destinationType) +943
   System.Data.SqlClient.SqlParameter.GetCoercedValue() +29
   System.Data.SqlClient.SqlParameter.Validate(Int32 index, Boolean isCommandProc) +97
   System.Data.SqlClient.SqlCommand.BuildParamList(TdsParser parser, SqlParameterCollection parameters) +166
   System.Data.SqlClient.SqlCommand.BuildExecuteSql(CommandBehavior behavior, String commandText, SqlParameterCollection parameters, _SqlRPC& rpc) +253
   System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1005
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +132
   System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method) +32
   System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior, String method) +122
   System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior) +12
   System.Data.Common.DbCommand.System.Data.IDbCommand.ExecuteReader(CommandBehavior behavior) +7
   System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +141
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +137
   System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, String srcTable) +83
   System.Web.UI.WebControls.SqlDataSourceView.ExecuteSelect(DataSourceSelectArguments arguments) +1770
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +17
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +149
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +70
   System.Web.UI.WebControls.GridView.DataBind() +4
   System.Web.UI.WebControls.BaseDataBoundControl.EnsureDataBound() +82
   System.Web.UI.WebControls.CompositeDataBoundControl.CreateChildControls() +69
   System.Web.UI.Control.EnsureChildControls() +87
   System.Web.UI.Control.PreRenderRecursiveInternal() +50
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Control.PreRenderRecursiveInternal() +170
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2041
Open in New Window
 
 
20080716-EE-VQP-32 / EE_QW_2_20070628