2

我有一个从 sqldatasource 填充的 asp.net 下拉列表。我的问题是第一个选项必须是(全部)。无论如何要在 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>

谢谢!

4

1 回答 1

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

于 2012-04-30T17:16:28.253 回答