【问题标题】:Gridview issue using a dropdownlist使用下拉列表的 Gridview 问题
【发布时间】:2012-02-26 23:21:21
【问题描述】:

我使用下拉列表来优化我的 GridView。 Dropdownlist 绑定到 AccessDataSource(表类别)并有一个虚拟字段(请选择)。

<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(产品表)绑定到下拉列表,并将结果分别返回给选定的下拉列表值。但是,如果选择了虚拟字段 - 不返回数据(下拉列表中没有匹配的 CategoryID - 它的值为 null)

如何在选择伪字段时返回GridView中的所有记录?

感谢您的帮助。

【问题讨论】:

  • 你的SELECT 声明是什么样的?
  • SELECT [Product_Id], [ProductName], [Price], [ReleaseDate], [Promotion], [Genre_Id], [Category_Id] FROM [tblProduct] WHERE ([Category_Id] = ?) as I提到的参数来源是下拉列表(选择值)

标签: asp.net gridview


【解决方案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

【讨论】:

  • 非常感谢。现在它默认返回所有记录,我还可以应用一些过滤器
猜你喜欢
  • 1970-01-01
  • 2014-10-04
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-25
  • 1970-01-01
  • 2012-07-09
  • 1970-01-01
相关资源
最近更新 更多