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

2013 年 8 月 18 日4520

<form runat="server">
 <div>
 <h2>Select an Order from the Left...</h2>
 <asp:SqlDataSource Runat="server"
  SelectCommand="SELECT dbo.Orders.OrderID,
  dbo.Customers.CompanyName, dbo.Orders.OrderDate FROM
  dbo.Orders INNER JOIN dbo.Customers ON dbo.Orders.CustomerID = dbo.Customers.CustomerID"
  ConnectionString=
    "<%$ ConnectionStrings:NWConnectionString %>">
 </asp:SqlDataSource>
 <asp:GridView Runat="server"
  DataSourceID="ordersDataSource" DataKeyNames="OrderID"
  AutoGenerateColumns="False" AllowPaging="True"
  BorderWidth="1px" BackColor="#DEBA84"
  CellPadding="3" CellSpacing="2" BorderStyle="None"
  BorderColor="#DEBA84"
  OnPageIndexChanged="orderGridView_PageIndexChanged">
 <FooterStyle ForeColor="#8C4510"
  BackColor="#F7DFB5"></FooterStyle>
  <PagerStyle ForeColor="#8C4510"
   HorizontalAlign="Center"></PagerStyle>
  <HeaderStyle ForeColor="White" Font-Bold="True"
   BackColor="#A55129"></HeaderStyle>
 <Columns>
  <asp:CommandField ShowSelectButton="True"
    SelectText="View Order Details"></asp:CommandField>
  <asp:BoundField HeaderText="Company"
    DataField="CompanyName"
    SortExpression="CompanyName"></asp:BoundField>
  <asp:BoundField HeaderText="Order Date"
    DataField="OrderDate" SortExpression="OrderDate"
    DataFormatString="{0:d}">
   <ItemStyle HorizontalAlign="Right"></ItemStyle>
  </asp:BoundField>
 </Columns>
 <SelectedRowStyle ForeColor="White" Font-Bold="True"
   BackColor="#738A9C"></SelectedRowStyle>
  <RowStyle ForeColor="#8C4510" BackColor="#FFF7E7"></RowStyle>
 </asp:GridView>
</div>
<div>
<h2>... and View the Order Details on the Right</h2>
<asp:SqlDataSource Runat="server"
 SelectCommand="SELECT dbo.[Order Details].OrderID,
 dbo.Products.ProductName, dbo.[Order Details].UnitPrice,
 dbo.[Order Details].Quantity, dbo.[Order Details].Discount
 FROM dbo.[Order Details] INNER JOIN dbo.Products
 ON dbo.[Order Details].ProductID = dbo.Products.ProductID
 WHERE dbo.[Order Details].OrderID = @OrderID"
 ConnectionString="<%$ ConnectionStrings:NWConnectionString %>">
<SelectParameters>
 <asp:ControlParameter ControlID="orderGridView"
  Name="OrderID" Type="Int32"
  PropertyName="SelectedValue" />
</SelectParameters>
</asp:SqlDataSource>

<asp:GridView Runat="server"
 DataSourceID="orderDetailsDataSource"
 AutoGenerateColumns="False" BorderWidth="1px"
 BackColor="#DEBA84" CellPadding="3"
 CellSpacing="2" BorderStyle="None" BorderColor="#DEBA84">
 <FooterStyle ForeColor="#8C4510" BackColor="#F7DFB5"></FooterStyle>
 <PagerStyle ForeColor="#8C4510" HorizontalAlign="Center"></PagerStyle>
 <HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#A55129"></HeaderStyle>
 <Columns>
<asp:BoundField HeaderText="Product"
 DataField="ProductName"
 SortExpression="ProductName"></asp:BoundField>
<asp:BoundField HeaderText="Unit Price"
 DataField="UnitPrice" SortExpression="UnitPrice"
 DataFormatString="{0:c}">
 <ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Quantity"
 DataField="Quantity" SortExpression="Quantity">
 <ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
<asp:BoundField HeaderText="Discount"
 DataField="Discount" SortExpression="Discount"
 DataFormatString="{0:P}">
<ItemStyle HorizontalAlign="Right"></ItemStyle>
</asp:BoundField>
</Columns>
<SelectedRowStyle ForeColor="White" Font-Bold="True"
 BackColor="#738A9C"></SelectedRowStyle>
<RowStyle ForeColor="#8C4510" BackColor="#FFF7E7"></RowStyle>
</asp:GridView>
</div>
</form>

0 0