Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

ASP Dropdownlists - link each dropdownlist to the next

Posted on 2011-05-04
9
Medium Priority
?
261 Views
Last Modified: 2012-06-27
Hi,

I have created 3 dropdown lists that i want to have linked to each other.  I have "Company", "Employee" and "Rule".  If the user selects a company, only the employees of that company must be in the "Employee" dropdownlist, and then only the rules that apply to that employee must be in the "Rules" dropdownlist.

Now, I had originally created 1 dataSource, and used one query to get this result, but I am getting duplicate records in the drop down list.  for instance, I am getting 4 copies of the company name, 2 copies of the employee name.

How can I fix this?
<asp:DropDownList ID="DropDownList8" runat="server" 
                DataSourceID="SqlDataSource1" DataTextField="FullName" DataValueField="FullName" 
                Height="21px" Width="182px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                ConnectionString="<%$ ConnectionStrings:ConnectionString %>" 
SelectCommand="SELECT CompanyDetails.Name As Company, Personnel.Name + ' ' + Personnel.Surname AS FullName,
 Rules.Name As Rules 
FROM Personnel INNER JOIN CompanyDetails ON Personnel.owner_ID = CompanyDetails.ID
INNER JOIN Emp_Shift ON Emp_Shift.Employee_ID = Personnel.Personel_ID
INNER JOIN Rules_ShiftRulesGroup ON Rules.Rules_ID = Emp_Shift.Rules_ID 
">
</asp:SqlDataSource>
</td>
<td class="style15">
<asp:Label ID="Label1" runat="server" Font-Size="Medium" Text="Select Rule:"></asp:Label></td>
<td width="20%" class="style7">

<asp:DropDownList ID="DropDownList6" runat="server" 
    DataSourceID="SqlDataSource1" DataTextField="ShiftRulesGroup" 
DataValueField="ShiftRulesGroup" Height="21px" Width="183px">
</asp:DropDownList>
</td>
<asp:DropDownList ID="DropDownList9" runat="server" 
  DataSourceID="SqlDataSource1" DataTextField="FullName" 
  DataValueField="FullName" Width="178px">
</asp:DropDownList>

Open in new window

0
Comment
Question by:NerishaB
  • 5
  • 3
9 Comments
 
LVL 4

Expert Comment

by:qasim_md
ID: 35688693
Use the DISTINCT condition or split the query to load the 3 drop down list seperately.
0
 

Author Comment

by:NerishaB
ID: 35688787
I tried the distinct condition, that does not work.

Do you mean, add 3 seperate datasources?  if I do that, I will get a list of all the companies, then all the the employees, then all the rules, which is not exactly what I need.
0
 
LVL 1

Expert Comment

by:swarg
ID: 35688856
Create 3 queries
first query with all company listed in dropdown As soon as you select the company pass the company id to the second query to get the list of employees of specific company same way pass employee selected value to 3 query and you will get the rule list.
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:NerishaB
ID: 35688944
Can you give me an example of how to pass the company id to the secondary query?
0
 
LVL 1

Accepted Solution

by:
swarg earned 1500 total points
ID: 35689067
0
 

Author Comment

by:NerishaB
ID: 35689464
Any easier methods?
0
 

Author Comment

by:NerishaB
ID: 35689635
Can anyone porvide me with more detail on how to do this?
0
 

Author Closing Comment

by:NerishaB
ID: 35830222
Thanks for the help.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

564 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question