Click here to Skip to main content
15,915,763 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Dear all I am having a go at Using ASP.Net forms.

To state my requirments

I need to create a form that enables users to read from one SQL table and write to another, I belive I have this part covered except for a major issue.

I understand and have added the two data sources which display both sets of columns but am uncertain of how to go about mapping the tables. The problem is, as a new student is added to the table on the left the rows would become de synchronised.

Additionally I need to drill down on the masses of information stored in these databases, so I have created a landing page with 3 drop down lists that map to SQL however I am unsure of how to pass on the infomation to the 2nd - 3rd drop down box to create a view based on the selections.

Please see my current code below.

C#
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true"
    CodeFile="Default.aspx.cs" Inherits="_Default" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent">
</asp:Content>
<asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent">
    <asp:DropDownList ID="DropDownList1" runat="server"
        DataSourceID="SqlDataSource1" DataTextField="DeptName" DataValueField="SID">
    </asp:DropDownList>
    <br />
    <asp:DropDownList ID="DropDownList2" runat="server"
        DataSourceID="SqlDataSource2" DataTextField="DeptName" DataValueField="SID">
    </asp:DropDownList>
    <br />
    <asp:DropDownList ID="DropDownList3" runat="server"
        DataSourceID="SqlDataSource3" DataTextField="OfferingCode"
        DataValueField="OfferingID">
    </asp:DropDownList>
    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:BISConnectionString %>" SelectCommand="SELECT DISTINCT CL.SID, CL.CODE AS DeptCode, CL.Name AS DeptName
FROM  ProSolution.dbo.CollegeLevel CL INNER JOIN [ProSolution].[dbo].[StaffCollegeLevelMembership] AS SCLM
ON CL.SID = SCLM.SID INNER JOIN ProSolution.dbo.Staff AS S
ON SCLM.StaffID = S.StaffID
WHERE (CL.SID &lt;&gt; '0')
AND (CL.LevelNum = '1')
AND (CL.Enabled = '1')
AND (CL.MaxAcademicYearID IS NULL)
AND (RTRIM(Code) NOT IN ('PHY', 'PY2', 'PYE', 'PYW', 'CDU'))
ORDER BY DeptCode"></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource2" runat="server"
        ConnectionString="<%$ ConnectionStrings:BISConnectionString %>" SelectCommand="
SELECT DISTINCT CL.SID, CL.Code AS DeptCode, CL.Name AS DeptName
FROM [ProSolution].[dbo].Staff AS S INNER JOIN [ProSolution].[dbo].StaffCollegeLevelMembership AS SCLM
ON S.StaffID = SCLM.StaffID RIGHT OUTER JOIN [ProSolution].[dbo].CollegeLevel AS CL
ON SCLM.SID = CL.SID
WHERE (CL.SID &lt;&gt; '0')
AND (CL.LevelNum = '2')
AND (CL.Enabled = '1')
AND (CL.MaxAcademicYearID IS NULL)
ORDER BY DeptCode            "></asp:SqlDataSource>
    <asp:SqlDataSource ID="SqlDataSource3" runat="server"
        ConnectionString="<%$ ConnectionStrings:BISConnectionString %>" SelectCommand="SELECT DISTINCT O.OfferingID AS OfferingID, O.AcademicYearID, O.Code AS OfferingCode,
O.Name AS OfferingName, OS.Description AS OfferingStatus
FROM ProSolution.dbo.Offering AS O INNER JOIN ProSolution.dbo.OfferingStatus AS OS
ON O.OfferingStatusID = OS.OfferingStatusID INNER JOIN [BIS].[dbo].[vIP_FunctionalSkillsEnrolments_14] AS VFS
ON O.OfferingID = VFS.OfferingID
WHERE O.AcademicYearID = '14/15'
ORDER BY OfferingName"></asp:SqlDataSource>
</asp:Content>


Any suggestions are greatly appreciated.

Regards,

Michael.
Posted

use AutoPostBack='true' and the OnSelectionIndexChanged events for the DropDownLists
In these events you can check what the values of the other selected DropDowns are and use these values in your queries
 
Share this answer
 
Comments
Michael Arthey 30-Oct-14 4:27am    
Thank you digimanus. Could you provide an example of how you put the Indexed value in the SQL query? Thank you.
Herman<T>.Instance 30-Oct-14 4:47am    
Is there any reason you are not using your codebehind file? When you use events you need the codebehind. You could easily use your SQL there too.
Michael Arthey 30-Oct-14 4:49am    
Yes. I forgot to mention I am new to asp.net. I have done an asp form in the past but. This is my first ASP.net form. This is something I would really like to implement in our college going forward as there is a lot of reliance on connecting directly to SQL here. Thanks for any further input.
Herman<T>.Instance 30-Oct-14 5:13am    
Well..use the codebehind! and read about ado.net en the use of SqlParameters
Michael Arthey 30-Oct-14 5:29am    
Ok will do. I am familiar with SqlParameters as I am using them to populate the dropdownlist e.g..

SELECT DISTINCT CL.SID, CL.CODE AS DeptCode, CL.Name AS DeptName
FROM ProSolution.dbo.CollegeLevel CL INNER JOIN [ProSolution].[dbo].[StaffCollegeLevelMembership] AS SCLM
ON CL.SID = SCLM.SID INNER JOIN ProSolution.dbo.Staff AS S
ON SCLM.StaffID = S.StaffID
WHERE (CL.SID <> '0')
AND (CL.LevelNum = '1')
AND (CL.Enabled = '1')
AND (CL.MaxAcademicYearID IS NULL)
AND (RTRIM(Code) NOT IN ('PHY', 'PY2', 'PYE', 'PYW', 'CDU'))
ORDER BY DeptCode

I just need to be able to pass this information from dropdownlist1 to dropdownlist2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900