将项添加到Gridview的EditItemTemplate中的DropDownList

时间:2016-02-10 16:56:09

标签: javascript c# html asp.net

我正在尝试使用codebehind或javascript找到将项添加到下拉列表的方法。 下拉列表位于编辑项目部分的网格视图中

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

1 个答案:

答案 0 :(得分: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;
}