2017-07-27 33 views
0

我有dropdownlist綁定到數據庫。我想添加數據庫中不存在的其他列表項。我能爲它做些什麼?數據時將默認值添加到asp.net中的dropdownlist

<asp:DropDownList ID="dpl_goalGallery" runat="server" CssClass="axmor-form-field selectType" AutoPostBack="True" Font-Size="14px" DataSourceID="ds_sourceGallery" DataTextField="galleryTitle" DataValueField="galleryId"> 
    <asp:ListItem>select...</asp:ListItem> 
    </asp:DropDownList> 

    <asp:SqlDataSource ID="ds_goalGallery" runat="server" ConnectionString="<%$ ConnectionStrings:anaconnection %>" SelectCommand="sp_select_gallery" SelectCommandType="StoredProcedure"> 
     <SelectParameters> 
      <asp:Parameter DefaultValue="0" Name="act" Type="Int32" /> 
      <asp:Parameter DefaultValue=" " Name="fromDate" Type="String" /> 
      <asp:Parameter DefaultValue=" " Name="toDate" Type="String" /> 
     </SelectParameters> 
    </asp:SqlDataSource> 
</asp:DropDownList> 

回答

0

你可以這樣做綁定: 感謝

我的下拉列表

dpl_goalGallery.Items.Insert(0, new ListItem("Select","NA") 

或者你可以添加默認標記爲

<asp:DropDownList .. AppendDataBoundItems="true"> 
    <Items> 
     <asp:ListItem Text="Select" Value="" /> 
    </Items> 
</asp:DropDownList> 
+0

謝謝!它非常有用。 –