2014-05-15 31 views
1

因此,我製作了一個帶有下拉列表的Web表單,其中包含學校中的不同類,如果您選擇一個,則可以在下面的GridView中獲得所選類的所有學生。所以我現在想做的是,如果我點擊一個學生,它應該打開一個關於學生的更詳細的頁面,但我沒有線索如何做到這一點。我獲得了一個.mdf數據庫文件的所有數據。gridview中每個條目的詳細信息

<%@ 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

0

一個更方便的方法來做到這一點,而不創建一個新的頁面將是將數據填充到引導模式像this。它使用UpdatePanel,它可能或不可能是你想要使用的東西。

  1. 將細節事件添加到Gridview。
  2. 使用FormView爲Bootstrap模式創建div
  3. 從後面的C#代碼中調用jQuery,使用GridView中的ID填充FormView中的數據。