fn27
fn27

Reputation: 879

Gridview issue using a dropdownlist

I use dropdownlist to refine my GridView. Dropdownlist is bind to AccessDataSource (table categories) and has a dummy field (Please select).

<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>

The GridView (product table) is bind to dropdownlist and returns results respectively to the selected dropdownlist value. However, if dummy field is selected - No data is returned (there are no matching CategoryID from dropdownlist - its value is null)

How can I simply return all records in GridView when dummy field is selected??

Thanks for any help.

Upvotes: 2

Views: 321

Answers (1)

pete
pete

Reputation: 25081

Change the SELECT statement to SELECT [Product_Id], [ProductName], [Price], [ReleaseDate], [Promotion], [Genre_Id], [Category_Id] FROM [tblProduct] WHERE ([Category_Id] = @Category_Id OR @Category_Id IS NULL) and set the CancelSelectOnNullParameter property of the AccessDataSource to False.

Upvotes: 1

Related Questions