2016-02-10 34 views
0

我正試圖找到一種方法使用代碼隱藏或JavaScript將項目添加到下拉列表。 的下拉列表位於編輯項部分中的GridView控件裏將項目添加到GridView的EditItemTemplate中的DropDownList

<asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" DataKeyNames="pallet" DataSourceID="RFS_TW" AllowPaging="True" Width="100%"> 
    <AlternatingRowStyle BackColor="White"></AlternatingRowStyle> 

    <Columns> 
     <asp:CommandField ShowEditButton="True" /> 
     <asp:BoundField DataField="pallet" HeaderText="Pallet" ReadOnly="True" SortExpression="pallet" ItemStyle-Width="10%" > 
     <ItemStyle Width="10%" /> 
     </asp:BoundField> 
     <asp:BoundField DataField="date_added" HeaderText="Date" SortExpression="date_added" ReadOnly="True" ItemStyle-Width="10%"> 
     <ItemStyle Width="10%" /> 
     </asp:BoundField> 
     <asp:BoundField DataField="department" HeaderText="Department" SortExpression="department" ReadOnly="True" ItemStyle-Width="10%"> 
     <ItemStyle Width="10%" /> 
     </asp:BoundField> 

     <asp:TemplateField HeaderText="sold_by" SortExpression="sold_by"> 
      <EditItemTemplate> 
       <asp:DropDownList ID="soldby_ddl" runat="server" > 
        <asp:ListItem>Please Select</asp:ListItem> 
       </asp:DropDownList> 
      </EditItemTemplate> 
      <ItemTemplate> 
       <asp:Label ID="Label2" runat="server" Text='<%# Bind("sold_by") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Width="10%" /> 
     </asp:TemplateField> 
    </Columns> 
</asp:GridView> 

回答

0

嘗試使用

function addValues() { 
    var listBox = document.getElementById("soldby_ddl"); 
    var option = new Option("value", "value"); 
    listBox.appendChild(option); 
} 

function addValues() { 
    var listBox = document.getElementById("soldby_ddl"); 
    var option = new Option("value", "value"); 
    listBox.options[i++] = option; 
} 
+0

沒有工作。我嘗試都 –

+0

第一個:無法獲取屬性'appendChild'的未定義或空引用 –

+0

第二:JavaScript運行時錯誤:無法獲取未定義或空引用的屬性'選項' –

相關問題