How to retreive data from the database to the second table after selecting the user in the first table?
<p>I have three tables in my database as following:</p>

<p><strong>Employee Table: Username, Name, Job, DivisonCode</strong> </p>

<p><strong>Course Table: CourseID, CourseName, GroupID</strong>  </p>

<p><strong>Employee_Course Table: Username, CourseID (The first key in each table is the primary key)</strong></p>

<p>I created two ListViews; one for retrieving the employee information from the Employee Table and the second one to show the taken courses (from Employee_Course Table) of the selected employee in the first ListView.</p>

<p>For the first table, everything works well and fine, but for the second table, I could not be able to retrieve the taken courses of the selected employee in the first table. </p>

<p><strong>So how can I do that?</strong></p>

<p>My ASP.NET code:</p>

<pre><code>&lt;asp:ListView ID="ListView1" runat="server" DataKeyNames="Username" 
            DataSourceID="SqlDataSource1" InsertItemPosition="LastItem"&gt;

            &lt;EditItemTemplate&gt;
                &lt;tr style=""&gt;
                    &lt;td&gt;
                        &lt;asp:ImageButton ID="UpdateButton" ImageUrl="images/update4.png" Width="20px" runat="server" CommandName="Update" /&gt;
                        &lt;asp:ImageButton ID="CancelButton" ImageUrl="images/cancel.png" Width="20px" runat="server" CommandName="Cancel" /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="NameTextBox" runat="server" Text='&lt;%# Bind("Name") %&gt;' /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:Label ID="UsernameLabel1" runat="server" Text='&lt;%# Eval("Username") %&gt;' /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="JobTitleTextBox" runat="server" 
                            Text='&lt;%# Bind("JobTitle") %&gt;' /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="BadgeNoTextBox" runat="server" Text='&lt;%# Bind("BadgeNo") %&gt;' /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:TextBox ID="EmpOrgTypeTextBox" runat="server" 
                            Text='&lt;%# Bind("EmpOrgType") %&gt;' /&gt;
                    &lt;/td&gt;
                    &lt;td&gt;
                        &lt;asp:DropDownList ID="DropDownList1" runat="server" SelectedValue='&lt;%# Bind("DivisionCode") %&gt;' 
                            DataSourceID="SqlDataSource1" DataTextField="DivisionName" 
                            DataValueField="SapCode"&gt;
                        &lt;/asp:DropDownList&gt;
                        &lt;asp:SqlDataSource ID="SqlDataSource1" runat="server" 
                            ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" 
                            DeleteCommand="DELETE FROM [Divisions] WHERE [SapCode] = @SapCode" 
                            InsertCommand="INSERT INTO [Divisions] ([SapCode], [DivisionName]) VALUES (@SapCode, @DivisionName)" 
                            SelectCommand="SELECT * FROM [Divisions]" 
                            UpdateCommand="UPDATE [Divisions] SET [DivisionName] = @DivisionName WHERE [SapCode] = @SapCode"&gt;
                            &lt;DeleteParameters&gt;
                                &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                            &lt;/DeleteParameters&gt;
                            &lt;InsertParameters&gt;
                                &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                                &lt;asp:Parameter Name="DivisionName" Type="String" /&gt;
                            &lt;/InsertParameters&gt;
                            &lt;UpdateParameters&gt;
                                &lt;asp:Parameter Name="DivisionName" Type="String" /&gt;
                                &lt;asp:Parameter Name="SapCode" Type="Double" /&gt;
                            &lt;/UpdateParameters&gt;
                        &lt;/asp:SqlDataSource&gt;
                    &lt;/td&gt;
                &lt;/tr&gt;
            &lt;/EditItemTemplate&gt;
            &lt;EmptyDataTemplate&gt;
                &lt;table runat="server" style=""&gt;
                    &lt;tr&gt;
                        &lt;td&gt;
                            No data was returned.&lt;/td&gt;
                    &lt;/tr&gt;
                &lt;/table&gt;
            &lt;/EmptyDataTemplate&gt;

        &lt;/asp:ListView&gt;
        &lt;asp:SqlDataSource ID="SqlDataSource2" runat="server" 
            ConnectionString="&lt;%$ ConnectionStrings:testConnectionString %&gt;" 
            DeleteCommand="DELETE FROM [employee_courses] WHERE [ID] = @ID" 
            InsertCommand="INSERT INTO [employee_courses] ([employeeId], [courseId]) VALUES (@employeeId, @courseId)" 
            SelectCommand="SELECT * FROM [employee_courses] WHERE ([employeeId] = @Username)" 
            UpdateCommand="UPDATE [employee_courses] SET [employeeId] = @employeeId, [courseId] = @courseId WHERE [ID] = @ID"&gt;
            &lt;DeleteParameters&gt;
                &lt;asp:Parameter Name="ID" Type="Int32" /&gt;
            &lt;/DeleteParameters&gt;
            &lt;InsertParameters&gt;
                &lt;asp:Parameter Name="employeeId" Type="String" /&gt;
                &lt;asp:Parameter Name="courseId" Type="Int32" /&gt;
                &lt;asp:ControlParameter ControlID="ListView1" Name="Username" PropertyName="SelectedValue" Type="String" /&gt;
            &lt;/InsertParameters&gt;
            &lt;SelectParameters&gt;
                &lt;asp:ControlParameter ControlID="ListView1" Name="Username" 
                    PropertyName="SelectedValue" Type="String" /&gt;
            &lt;/SelectParameters&gt;
            &lt;UpdateParameters&gt;
                &lt;%--&lt;asp:Parameter Name="employeeId" Type="String" /&gt;--%&gt;
                &lt;asp:Parameter Name="courseId" Type="Int32" /&gt;
                &lt;asp:Parameter Name="ID" Type="Int32" /&gt;
            &lt;/UpdateParameters&gt;
        &lt;/asp:SqlDataSource&gt;
</code></pre>
