我公司目前已與查詢字符串下面的語句設置爲產品分類我的ListView控件:如何在1個DataSource上添加多個SQL語句/查詢字符串?
SELECT * FROM Products WHERE (ProductCategory = ?)
我想補充在同一個數據源這一說法,並查詢字符串,以允許產品型號查詢字符串,又怎麼能我這樣做?
SELECT * FROM Products WHERE (ProductModel = ?)
的ListView
<asp:ListView runat="server" ID="listView" GroupItemCount="3"
DataSourceID="AccessDataSource1">
<LayoutTemplate>
<div style="height: 966px;">
<div style="width: 771px;">
<asp:PlaceHolder runat="server" ID="groupPlaceHolder" />
<asp:DataPager runat="server" ID="dpMyDatePager" PageSize="9"
PagedControlID="listView">
<Fields>
<asp:NextPreviousPagerField ButtonType="Button" ShowLastPageButton="True"
ShowFirstPageButton="True" />
<asp:NumericPagerField />
</Fields>
</asp:DataPager>
</div>
</LayoutTemplate>
<GroupTemplate>
<div style="clear: both;">
<asp:PlaceHolder runat="server" ID="itemPlaceHolder" />
</div>
</GroupTemplate>
<ItemTemplate>
<div class="productItem">
<div>
<img src='<%# Eval("ProductUrl") %>' >
</div>
<div class="catalog-price">
<br />
<%# Eval("ProductBrand") %>
<%# Eval("ProductModel") %></div>
<div class="catalog-price2">
<b>
Our Price: S$<%# Eval("NormalPrice") %></div>
</b><br />
<div class="cell1">
Add to cart</div>
<div class="cell2">
<asp:HyperLink ID="HypViewDetails" style="text-decoration:none" NavigateUrl='<%#Eval("ProductId", "ProductDetails.aspx?ProductID={0}")%>'
runat="server">View Details</asp:HyperLink>
</div>
</div>
</ItemTemplate>
<ItemSeparatorTemplate>
<div class="itemSeparator">
</div>
</ItemSeparatorTemplate>
<GroupSeparatorTemplate>
<div class="groupSeparator">
</div>
</GroupSeparatorTemplate>
<EmptyDataTemplate>
</EmptyDataTemplate>
</asp:ListView>
<asp:AccessDataSource ID="AccessDataSource1" runat="server"
DataFile="~/App_Data/TabStoreDB.mdb"
SelectCommand="SELECT * FROM Products WHERE (ProductCategory = ?) OR (ProductBrand = ?)">
<SelectParameters>
<asp:QueryStringParameter Name="?" QueryStringField="ProductCategory" />
<asp:QueryStringParameter Name="?" QueryStringField="ProductBrand" />
</SelectParameters>
</asp:AccessDataSource>
您好,我已經試過了上述說法,但是當我試圖訪問一個產品型號在我的ListView控件沒有出現例如。 Products.aspx?ProductModel = Acer – aurelio
我想你需要提供一些關於你想要做什麼的更多細節。你想通過ProductCategory或ProductModel進行搜索嗎? – Taryn
我希望能夠通過ProductCategory或ProductModel進行搜索。例如,當輸入Products.aspx?ProductCategory = Accessories時,ListView將顯示所有配件,並且在輸入Products.aspx?ProductModel = Acer時,ListView將顯示所有帶有型號'Acer'的產品 – aurelio