所以我创建了一个带有下拉列表的Web表单,其中包含学校中的不同课程,如果您选择一个,您将在下面的GridView中获得所选课程的所有学生。所以我现在要做的是,如果我点击一个学生,它应该打开一个关于学生的更详细的页面,但我没有线索如何做到这一点。我得到了.mdf数据库文件的所有数据。
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="schueler.aspx.cs" Inherits="ASPXUebung.schueler" %>
<asp:DropDownList ID="selectklassen" runat="server" DataSourceID="SqlDataSource1klassenselect" DataTextField="K_Bez" DataValueField="K_ID" AutoPostBack="true"></asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1klassenselect" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT [K_Bez], [K_ID] FROM [klassen] ORDER BY [K_Bez]"></asp:SqlDataSource>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1schueler" runat="server" ConflictDetection="CompareAllValues" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" DeleteCommand="DELETE FROM [schueler] WHERE [S_SCHNR] = @original_S_SCHNR AND (([S_Name] = @original_S_Name) OR ([S_Name] IS NULL AND @original_S_Name IS NULL)) AND (([S_Vorname] = @original_S_Vorname) OR ([S_Vorname] IS NULL AND @original_S_Vorname IS NULL)) AND (([S_Gebdat] = @original_S_Gebdat) OR ([S_Gebdat] IS NULL AND @original_S_Gebdat IS NULL)) AND (([S_Adresse] = @original_S_Adresse) OR ([S_Adresse] IS NULL AND @original_S_Adresse IS NULL)) AND (([S_K_Klasse] = @original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND @original_S_K_Klasse IS NULL))" InsertCommand="INSERT INTO [schueler] ([S_SCHNR], [S_Name], [S_Vorname], [S_Gebdat], [S_Adresse], [S_K_Klasse]) VALUES (@S_SCHNR, @S_Name, @S_Vorname, @S_Gebdat, @S_Adresse, @S_K_Klasse)" OldValuesParameterFormatString="original_{0}" SelectCommand="SELECT * FROM [schueler] WHERE ([S_K_Klasse] = @S_K_Klasse)" UpdateCommand="UPDATE [schueler] SET [S_Name] = @S_Name, [S_Vorname] = @S_Vorname, [S_Gebdat] = @S_Gebdat, [S_Adresse] = @S_Adresse, [S_K_Klasse] = @S_K_Klasse WHERE [S_SCHNR] = @original_S_SCHNR AND (([S_Name] = @original_S_Name) OR ([S_Name] IS NULL AND @original_S_Name IS NULL)) AND (([S_Vorname] = @original_S_Vorname) OR ([S_Vorname] IS NULL AND @original_S_Vorname IS NULL)) AND (([S_Gebdat] = @original_S_Gebdat) OR ([S_Gebdat] IS NULL AND @original_S_Gebdat IS NULL)) AND (([S_Adresse] = @original_S_Adresse) OR ([S_Adresse] IS NULL AND @original_S_Adresse IS NULL)) AND (([S_K_Klasse] = @original_S_K_Klasse) OR ([S_K_Klasse] IS NULL AND @original_S_K_Klasse IS NULL))">
<DeleteParameters>
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="S_SCHNR" Type="Int16" />
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
</InsertParameters>
<SelectParameters>
<asp:ControlParameter ControlID="selectklassen" Name="S_K_Klasse" PropertyName="SelectedValue" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="S_Name" Type="String" />
<asp:Parameter Name="S_Vorname" Type="String" />
<asp:Parameter Name="S_Gebdat" Type="DateTime" />
<asp:Parameter Name="S_Adresse" Type="String" />
<asp:Parameter Name="S_K_Klasse" Type="String" />
<asp:Parameter Name="original_S_SCHNR" Type="Int16" />
<asp:Parameter Name="original_S_Name" Type="String" />
<asp:Parameter Name="original_S_Vorname" Type="String" />
<asp:Parameter Name="original_S_Gebdat" Type="DateTime" />
<asp:Parameter Name="original_S_Adresse" Type="String" />
<asp:Parameter Name="original_S_K_Klasse" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
答案 0 :(得分:0)
将学生姓名列设为超链接列,如下所示:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="S_SCHNR" DataSourceID="SqlDataSource1schueler">
<Columns>
<asp:HyperLinkField DataNavigateUrlFields="S_SCHNR"
DataNavigateUrlFormatString="StudentInfo.aspx?id={0}
DataTextField="S_Name" "/>
<asp:BoundField DataField="S_SCHNR" HeaderText="S_SCHNR" ReadOnly="True" SortExpression="S_SCHNR" />
<asp:BoundField DataField="S_Name" HeaderText="S_Name" SortExpression="S_Name" />
<asp:BoundField DataField="S_Vorname" HeaderText="S_Vorname" SortExpression="S_Vorname" />
<asp:BoundField DataField="S_Gebdat" HeaderText="S_Gebdat" SortExpression="S_Gebdat" />
<asp:BoundField DataField="S_Adresse" HeaderText="S_Adresse" SortExpression="S_Adresse" />
<asp:BoundField DataField="S_K_Klasse" HeaderText="S_K_Klasse" SortExpression="S_K_Klasse" />
</Columns>
</asp:GridView>
制作另一个名为StudentInfo.aspx的网页。在该页面上,使用DetailsView控件,SqlDataSource控件和QueryString参数显示数据。以下是如何执行此操作的示例:http://msdn.microsoft.com/en-us/library/xt50s8kz(v=vs.100).aspx
答案 1 :(得分:0)
在不创建新页面的情况下,更方便的方法是将数据填充到像this这样的Bootstrap模式中。它使用UpdatePanel,它可能是您想要使用的东西,也可能不是。