我正在尝试将大学模块数据拉入gridview,但前提是该模块是强制性的。有谁知道怎么做?
以下是带有SQL数据源的ASPX代码:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False"
DataKeyNames="Module_Code" DataSourceID="SqlEnteringLevel">
<Columns>
<asp:BoundField DataField="Module_Code" HeaderText="Module_Code"
ReadOnly="True" SortExpression="Module_Code"></asp:BoundField>
<asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title">
</asp:BoundField>
<asp:BoundField DataField="Semester" HeaderText="Semester"
SortExpression="Semester"></asp:BoundField>
<asp:BoundField DataField="CATS" HeaderText="CATS" SortExpression="CATS">
</asp:BoundField>
<asp:CheckBoxField DataField="Compulsory" HeaderText="Compulsory"
SortExpression="Compulsory"></asp:CheckBoxField>
<asp:BoundField DataField="Course" HeaderText="Course" SortExpression="Course">
</asp:BoundField>
<asp:BoundField DataField="Level" HeaderText="Level" SortExpression="Level">
</asp:BoundField>
</Columns>
</asp:GridView>
<asp:button runat="server" text="Next" ID="BtnNext" TabIndex="1"/>
<asp:Button ID="BtnReturn" runat="server"
Text="Return to Registration Page" TabIndex="2" />
<asp:SqlDataSource ID="SqlCurrentLevel" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Level] FROM [Student_Academic_Record] WHERE ([Student_No] = @Student_No)">
<SelectParameters>
<asp:SessionParameter DefaultValue="Student" Name="Student_No"
SessionField="Student" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlEnteringLevel" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT DISTINCT Module_Details.Module_Code, Module_Details.Title, Module_Details.Semester, Module_Details.CATS, Module_Details.Compulsory, Student_Academic_Record.Course, Module_Timetable.Level FROM Module_Details INNER JOIN Module_Timetable ON Module_Details.Module_Code = Module_Timetable.Module_Code INNER JOIN Student_Academic_Record ON Module_Timetable.Course = Student_Academic_Record.Course WHERE (Module_Timetable.Level = @Level) AND (Student_Academic_Record.Course = @Course)">
<SelectParameters>
<asp:SessionParameter DefaultValue="EnteringLevel" Name="Level"
SessionField="EnteringLevel" />
<asp:SessionParameter DefaultValue="Course" Name="Course"
SessionField="Course" />
</SelectParameters>
</asp:SqlDataSource>
<asp:SqlDataSource ID="SqlCourse" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Course] FROM [Student_Academic_Record] WHERE ([Student_No] = @Student_No)">
<SelectParameters>
<asp:SessionParameter DefaultValue="Student" Name="Student_No"
SessionField="Student" Type="String" />
</SelectParameters>
</asp:SqlDataSource>
此时,根据登录的学生,显示与他们所进入的课程和级别相关的所有模块。
有人可以帮忙吗?
答案 0 :(得分:0)
您是否可以只更改SELECT
语句,以包含WHERE
字段的Compulsory
子句参数 - Module_Details.Compulsory = 1
,假设它是bit
列:< / p>
SelectCommand= _
"SELECT DISTINCT Module_Details.Module_Code, Module_Details.Title, " & _
"Module_Details.Semester, Module_Details.CATS, Module_Details.Compulsory, " & _
"Student_Academic_Record.Course, Module_Timetable.Level " & _
"FROM Module_Details " & _
"INNER JOIN Module_Timetable ON " & _
"Module_Details.Module_Code = Module_Timetable.Module_Code " & _
"INNER JOIN Student_Academic_Record ON " & _
"Module_Timetable.Course = Student_Academic_Record.Course " & _
"WHERE (Module_Timetable.Level = @Level) " & _
"AND (Student_Academic_Record.Course = @Course) " & _
"AND Module_Details.Compulsory = 1">
答案 1 :(得分:0)
如何简单地修改SqlDataSource SqlEnteringLevel
。
您的SelectCommand
应该是这样的。
SelectCommand="SELECT........WHERE (Module_Timetable.Level = @Level) AND
(Student_Academic_Record.Course = @Course)
AND (Module_Details.Compulsory = 'Compulsory')" // add this
因此,这将为您提供resultset
,其中只包含Compulsory
个模块。