2012-02-04 68 views
2

我使用dropdownlist來優化我的GridView。 Dropdownlist綁定到AccessDataSource(表類別)並有一個虛擬字段(請選擇)。Gridview問題使用下拉列表

<asp:Label ID="Label1" runat="server" Text="Refine your search"></asp:Label><br /> 
     <asp:DropDownList ID="ddlCategories" runat="server" AppendDataBoundItems="True" 
      AutoPostBack="True" DataSourceID="ADC_Categories" DataTextField="CatedName" 
      DataValueField="Categ_Id"> 
      <asp:ListItem Value="">-- please choose --</asp:ListItem> 
     </asp:DropDownList> 

GridView(產品表)綁定到dropdownlist並將結果分別返回到所選的dropdownlist值。但是,如果選擇了虛擬字段 - 沒有數據返回(從下拉列表中沒有匹配的CategoryID - 它的值爲空)

如何在選擇虛擬字段時簡單地返回GridView中的所有記錄?

感謝您的任何幫助。

+0

你的'SELECT'語句是什麼樣的? – pete 2012-02-04 19:50:07

+0

SELECT [Product_Id],[ProductName],[Price],[ReleaseDate],[Promotion],[Genre_Id],[Category_Id] FROM [tblProduct] WHERE([Category_Id] =?) 正如我所提到的參數source是dropdownlist (選定值) – fn27 2012-02-04 19:55:48

回答

1

更改SELECT聲明SELECT [Product_Id], [ProductName], [Price], [ReleaseDate], [Promotion], [Genre_Id], [Category_Id] FROM [tblProduct] WHERE ([Category_Id] = @Category_Id OR @Category_Id IS NULL)AccessDataSourceCancelSelectOnNullParameter屬性設置爲False

+0

非常感謝。現在它默認返回所有記錄,我也可以應用一些過濾器 – fn27 2012-02-04 20:13:30