简体   繁体   English

使用ASP.NET过滤器参数时如何添加空白列表项

[英]How to add a blank List Item when using asp.net filterparameters

A default list item has been added to each dropdown. 默认列表项已添加到每个下拉列表中。

When an option is selected from ddlA the items in ddlB will be filtered. 当一个选项选自ddlA中的项ddlB将被过滤。

PROBLEM 问题

When using the ASP.NET filter parameter the default list item value=0 will be removed/filtered out from ddlB . 使用ASP.NET过滤器参数时,将从ddlB删除/过滤出默认列表项value=0

QUESTION

How can the default list item be kept or re-added to ddlB when the list is filtered? 过滤列表后,如何保留默认列表项或将其重新添加到ddlB


DROPDOWNLIST 下拉列表

<asp:DropDownList ID="ddlA" runat="Server" DataSourceID="sqlA" DataTextField="TextA" DataValueField="ValueA" AppendDataBoundItems="true" AutoPostBack="true">
  <asp:ListItem Text="Select ..." Value="0"/>
</asp:DropDownList>

<asp:DropDownList ID="ddlB" runat="Server" DataSourceID="sqlB" DataTextField="TextB" DataValueField="ValueB" AppendDataBoundItems="true">
  <asp:ListItem Text="Select ..." Value="0"/>
</asp:DropDownList>

DATASOURCE 数据源

<asp:SqlDataSource ID="sqlA" runat="Server" SelectCommand="spA" SelectCommandType="StoredProcedure"/>

<asp:SqlDataSource ID="sqlB" runat="Server" SelectCommand="spB" SelectCommandType="StoredProcedure" FilterExpression="ValueA= '{0}'">
  <FilterParameters>
    <asp:ControlParameter Name="Col" ControlID="ddlA" PropertyName="SelectedValue"/>
  </FilterParameters>
</asp:SqlDataSource>

you will need to have this initial value in your data source so when creating datasource you will need to 您将需要在数据源中具有此初始值,因此在创建数据源时,您需要

SELECT 'Select' as TextA, 0 as ValueA
JOIN
Select TextA, ValueA from yourTable

these values will be bound to your DropDownLists and stay there and one more thing. 这些值将绑定到您的DropDownLists并停留在那里,还有一件事情。 Remember to remove filter before refiltering 记住在重新过滤之前要除去过滤器

SqlDataSource1.FilterExpression=""

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM