基于下拉列表(asp.net)生成动态Gridview

时间:2019-03-07 03:04:16

标签: asp.net

我正在尝试使自己的gridview动态生成基于下拉列表中的选择显示的内容。我似乎无法显示任何内容,尽管我看不出为什么情况并非如此。任何帮助将不胜感激。

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="ticketSales.aspx.cs" Inherits="CSC340.ticketSales" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <link href="styles/bootstrap.min.css" rel="stylesheet" />
    <link href="styles/tickets.css" rel="stylesheet" />
</head>
<body>
    <div class="container">
    <header class="jumbotron">
    </header> 
    <main>
        <form id="form1" runat="server" class="form-horizontal" role="form">
        <h2>Airline Tickets by Eric R</h2>
            <div>
                Select a passenger:
                <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" DataSourceID="SqlDataSource1" DataTextField="lastName" DataValueField="lastName"></asp:DropDownList>
            </div>  
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ticketid" DataSourceID="SqlDataSource1" cssclass="table table-bordered table-striped">
                <Columns>
                    <asp:BoundField DataField="ticketid" HeaderText="ticketid" ReadOnly="True" SortExpression="ticketid"></asp:BoundField>
                    <asp:BoundField DataField="purchaseDate" HeaderText="purchaseDate" SortExpression="purchaseDate"></asp:BoundField>
                    <asp:BoundField DataField="pricepaid" HeaderText="pricepaid" SortExpression="pricepaid"></asp:BoundField>
                    <asp:BoundField DataField="sales_channel" HeaderText="sales_channel" SortExpression="sales_channel"></asp:BoundField>
                    <asp:BoundField DataField="farebasisIDFK" HeaderText="farebasisIDFK" SortExpression="farebasisIDFK"></asp:BoundField>
                    <asp:BoundField DataField="restrictions" HeaderText="restrictions" SortExpression="restrictions"></asp:BoundField>
                    <asp:BoundField DataField="passengerid" HeaderText="passengerid" SortExpression="passengerid"></asp:BoundField>
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource runat="server" ID="SqlDataSource1" ConnectionString='<%$ ConnectionStrings:ConnectionString %>' SelectCommand="SELECT ticket.ticketid, ticket.sales_channel, ticket.pricepaid, ticket.passengerid, ticket.farebasisIDFK, ticket.purchaseDate, passenger.lastName, passenger.firstName, farebasis.restrictions, passenger.passengerid AS Expr1 FROM ticket INNER JOIN passenger ON ticket.passengerid = passenger.passengerid AND ticket.passengerid = passenger.passengerid INNER JOIN farebasis ON ticket.farebasisIDFK = farebasis.farebasisID WHERE (passenger.lastName = @lastName)">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" PropertyName="SelectedValue" Name="lastName"></asp:ControlParameter>
                </SelectParameters>
            </asp:SqlDataSource>
        </form>
    </main>
    </div>
</body>
</html>

0 个答案:

没有答案