向下拉列表添加额外选项

时间:2012-04-30 17:02:47

标签: asp.net

我有一个asp.net下拉列表,从sqldatasource填充。我的问题是第一个选项需要是(全部)。无论如何要在eqldatasource列表之前将这个额外的选项添加到列表中吗?

     <asp:DropDownList ID="REGIONS" runat="server" 
      Width="70px"  AutoPostBack="True" DataTextField="REGION_CD" 
      DataValueField="REGION_CD" DataSourceID="SqlDataSource1"  >
     </asp:DropDownList>

     <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
      ConnectionString="<%$ ConnectionStrings:PRODUCTION %>" 
      ProviderName="<%$ ConnectionStrings:PRODUCTION.ProviderName %>" 
      SelectCommand="select distinct(region_cd) from mv_gauge_filter_dist where     region_cd is not null">
  </asp:SqlDataSource>

感谢名单!

1 个答案:

答案 0 :(得分:4)

未经测试,但这应该有效:

<asp:DropDownList ID="REGIONS" AppendDataBoundItems="true" runat="server" 
  Width="70px"  AutoPostBack="True" DataTextField="REGION_CD" 
  DataValueField="REGION_CD" DataSourceID="SqlDataSource1"  >
  <asp:ListItem Text="ALL" Value="" />
 </asp:DropDownList>

 <asp:SqlDataSource ID="SqlDataSource1" runat="server" 
  ConnectionString="<%$ ConnectionStrings:PRODUCTION %>" 
  ProviderName="<%$ ConnectionStrings:PRODUCTION.ProviderName %>" 
  SelectCommand="select distinct(region_cd) from mv_gauge_filter_dist where region_cd is not null">
</asp:SqlDataSource>

记下AppendDataBoundItems =“true”......