Search code examples
gridview.net-2.0drop-down-menuedititemtemplate

DropDownList in GridView not available when Editing


I've got the setup below. When I click the 'Edit' link on the CommandField, a RowEditing event gets fired, but the row does not allow me to edit; specifically, the DropDownList does not appear.

My code seems to conform to all the examples I can find.

I'm probably missing something very basic, as I seem to be the only person on the internet having this problem. I'm desperate for another pair of eyes.

Thanks.

    <asp:GridView ID="grdvMachine1" runat="server" AutoGenerateColumns="False" CellSpacing="2"
    CssClass="GridViewFormat" GridLines="None" Width="500px"
    OnRowUpdating="grdvMachine1_RowUpdating" OnRowUpdated="grdvMachine1_RowUpdated"
    OnRowEditing="grdvMachine1_RowEditing" OnRowDeleting="grdvMachine1_RowDeleting">
    <PagerSettings Position="Top" />
    <FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
    <Columns>
        <asp:BoundField DataField="Day Of Week" HeaderText="Day Of Week" SortExpression="Day Of Week" />
        <asp:TemplateField HeaderText="Package" SortExpression="Package">
            <EditItemTemplate>
                <asp:DropDownList ID="comboPackageNames"
                    runat="server"
                    DataSourceID="PackageNames"
                    DataTextField="PackageName"
                    DataValueField="PackageName"
                    SelectedValue='<%# Bind("Package") %>'>
                </asp:DropDownList>
                <asp:ObjectDataSource ID="PackageNames" runat="server" SelectMethod="GetSPPList"
                    TypeName="PCS.WebApp.DefaultSchedules">
                </asp:ObjectDataSource>
            </EditItemTemplate>
             <ItemTemplate>
                <asp:Label ID="Label1" runat="server" Text='<%# Eval("Package") %>' />
            </ItemTemplate>
       </asp:TemplateField>
        <asp:CommandField ShowEditButton="true" ShowDeleteButton="true"/>
    </Columns>
    <RowStyle BackColor="#EEEEEE" ForeColor="Black" HorizontalAlign="Center" VerticalAlign="Middle" />
    <EmptyDataTemplate>
        There is no schedule for the selected machine
    </EmptyDataTemplate>
    <SelectedRowStyle BackColor="#008A8C" Font-Bold="False" ForeColor="White" />
    <PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
    <HeaderStyle BackColor="#000084" Font-Bold="True" ForeColor="White" HorizontalAlign="Center"
        VerticalAlign="Middle" />
    <AlternatingRowStyle BackColor="Gainsboro" />
</asp:GridView>

Solution

  • I didn't have an ObjectDataSource for the GridView. I was populating it in the code-behind, but apparently you can't do that and use a CommandField.