正 文

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


www.7dspace.com  更新日期:2005-10-8 8:23:09  七度空间


  可以看到,当选择dropdownlist中的不同商品时,gridview会显示涉及该商品的不同订单的详细资料.程序的代码如下:

<form id="form1" runat="server">
 <div>
 <h2>You are Viewing Order Detail Information for Orders
that Have Included Shipments of the Selected Product</h2>
 <asp:SqlDataSource ID="productListingDataSource"
    Runat="server" ConnectionString=
     "<%$ ConnectionStrings:NWConnectionString %>"
     SelectCommand="SELECT [ProductID],
     [ProductName] FROM [Products]">
 </asp:SqlDataSource>
 <asp:DropDownList ID="productSelector" Runat="server"
   DataSourceID="productListingDataSource"
   DataTextField="ProductName" DataValueField="ProductID"
   AutoPostBack="True">
 </asp:DropDownList> 
 <asp:SqlDataSource ID="orderDetailsForProduct" Runat="server"
   SelectCommand="SELECT [OrderID], [ProductID], [UnitPrice],
   [Quantity] FROM [Order Details] WHERE ([ProductID] =
   @ProductID)"
   ConnectionString=
     "<%$ ConnectionStrings:NWConnectionString%>"
     DataSourceMode="DataReader">
     <SelectParameters>
 <asp:ControlParameter Name="ProductID" Type="Int32"
   ControlID="productSelector"
   PropertyName="SelectedValue"></asp:ControlParameter>
 </SelectParameters>
 </asp:SqlDataSource><asp:GridView ID="orderDetailsGridView"
   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>
6页,页码:[1] [2] [3] [4] [5] [6] 

上一篇:代理服务器应用全攻略
下一篇:ASP.NET 2.0中Gridview控件高级技巧
作者:廖煜嵘编译  来源:天极网 ( 责任编辑:7dspace )
收藏此页】【打印】【关闭
站 内 搜 索
 

热 点 导 读
特 别 推 荐