熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> .NET編程 >> 正文

ASP.NET入門教程 13.2.4 產品項頁面[3]

2022-06-13   來源: .NET編程 

    操作回顧

    以和Product Catalog頁面基本相同的方法調整Product Item頁面主要的區別是沒有查看所有的商品而只希望查看某個商品的詳情如果查看源代碼將再次看到它由SqlDataSource和DataList控件組成

 

<form id=form runat=server>

    <div>

        <asp:SqlDataSource ID=SqlDataSource runat=server ConnectionString=<%$ ConnectionStrings:WroxUnitedConnectionString %>

            SelectCommand=SELECT DISTINCT [ProductID] [Name] [Description] [Price] [PictureURL] FROM [Products] WHERE ([ProductID] = @ProductID)>

            <SelectParameters>

                <asp:QueryStringParameter Name=ProductID QueryStringField=ProductID Type=Int />

            </SelectParameters>

        </asp:SqlDataSource>

   

    </div>

        <asp:DataList ID=DataList runat=server DataKeyField=ProductID DataSourceID=SqlDataSource>

            <ItemTemplate>

                <asp:Label Visible=false Text=<%# Eval(PictureURL) %> runat=server ID=PictureUrlLabel />

                <asp:Image ID=Image runat=server ImageUrl=<%# Eval(PictureURL ProductImages\{}) %> /><br />

                <asp:Label ID=NameLabel runat=server Text=<%# Eval(Name) %>></asp:Label><br />

                <asp:Label ID=DescriptionLabel runat=server Text=<%# Eval(Description) %>>

                </asp:Label><br />

                <asp:Label ID=PriceLabel runat=server Text=<%# Eval(Price {:##}) %>></asp:Label><br />

                <br />

                <br />

            </ItemTemplate>

        </asp:DataList>

        <asp:ImageButton ID=btnAddToCart runat=server OnClick=ImageButton_Click ImageUrl=~/Images/AddToCartgif /><br />

        <asp:HyperLink ID=HyperLink runat=server NavigateUrl=~/WroxShopaspx>Return to Shop</asp:HyperLink>

    </form>

[]  []  []  []  


From:http://tw.wingwit.com/Article/program/net/201311/15672.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.