ASP.NET2.0利用Gridview实现主从关系

2013 年 8 月 12 日3850

<form runat="server">
 <div>
 <h2>You are Viewing Order Detail Information for Orders
that Have Included Shipments of the Selected Product</h2>
 <asp:SqlDataSource
    Runat="server" ConnectionString=
     "<%$ ConnectionStrings:NWConnectionString %>"
     SelectCommand="SELECT [ProductID],
     [ProductName] FROM [Products]">
 </asp:SqlDataSource>
 <asp:DropDownList Runat="server"
   DataSourceID="productListingDataSource"
   DataTextField="ProductName" DataValueField="ProductID"
   AutoPostBack="True">
 </asp:DropDownList> 
 <asp:SqlDataSource Runat="server"
   SelectCommand="SELECT [OrderID], [ProductID], [UnitPrice],
   [Quantity] FROM [Order Details] WHERE ([ProductID] =
   @ProductID)"
   ConnectionString=
     "<%$ ConnectionStrings:NWConnectionString%>"
     DataSourceMode="DataReader">
     <SelectParameters>
 <asp:ControlParameter Type="Int32"
   ControlID="productSelector"
   PropertyName="SelectedValue"></asp:ControlParameter>
 </SelectParameters>
 </asp:SqlDataSource><asp:GridView
   Runat="server" DataSourceID="orderDetailsForProduct"
   AutoGenerateColumns="False" DataKeyNames="OrderID"
   BorderWidth="1px" BackColor="LightGoldenrodYellow"
   GridLines="None" CellPadding="2" BorderColor="Tan"
   ForeColor="Black">
 <FooterStyle BackColor="Tan"></FooterStyle>
 <PagerStyle ForeColor="DarkSlateBlue"
   HorizontalAlign="Center" BackColor="PaleGoldenrod">
 </PagerStyle>
 <HeaderStyle Font-Bold="True"
   BackColor="Tan"></HeaderStyle>
 <AlternatingRowStyle
   BackColor="PaleGoldenrod"></AlternatingRowStyle>
 <Columns>
  <asp:BoundField ReadOnly="True" HeaderText="Order ID"
    InsertVisible="False" DataField="OrderID"
    SortExpression="OrderID">
   <ItemStyle HorizontalAlign="Center"></ItemStyle>
  </asp:BoundField>
  <asp:BoundField HeaderText="Quantity"
    DataField="Quantity" SortExpression="Quantity"
    DataFormatString="{0:d}">
   <ItemStyle HorizontalAlign="Right"></ItemStyle>
  </asp:BoundField>
  <asp:BoundField HeaderText="Unit Price"
    DataField="UnitPrice" SortExpression="UnitPrice"
    DataFormatString="{0:c}">
    <ItemStyle HorizontalAlign="Right"></ItemStyle>
  </asp:BoundField>
 </Columns>
 <SelectedRowStyle ForeColor="GhostWhite"
  BackColor="DarkSlateBlue"></SelectedRowStyle>
</asp:GridView>
</div>
</form>

0 0