Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problems Using DropDownList inside an ItemTemplate
Message
De
03/04/2008 13:32:54
 
 
À
Tous
Information générale
Forum:
ASP.NET
Catégorie:
WebForms
Titre:
Problems Using DropDownList inside an ItemTemplate
Divers
Thread ID:
01307922
Message ID:
01307922
Vues:
62
Hi All.

I must have tajen my stupid pills today because I don't understand why this does not work. Any help would be appreciated.

Here is the HTML for my GridView:
 <asp:GridView ID="grdPhones" runat="server" AutoGenerateColumns="False" CellPadding="4"
            ForeColor="#333333" GridLines="None">
            <FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <Columns>
                <asp:CommandField ShowEditButton="True" />
                <asp:CommandField ShowDeleteButton="True" />
                <asp:TemplateField HeaderText="Phone Type">
                    <ItemTemplate>
                        <asp:DropDownList ID="ddlType" runat="server"></asp:DropDownList>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="cNumber" HeaderText="Phone Number" />
                <asp:BoundField DataField="iPhone_id" Visible="False" />
            </Columns>
            <RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
            <EditRowStyle BackColor="#999999" />
            <SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
            <PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
            <HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
            <AlternatingRowStyle BackColor="White" ForeColor="#284775" />
        </asp:GridView>
I want to populate the dropdown list in the phone types column using this code:
    protected void grdPhones_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            DropDownList ddl = (DropDownList)e.Row.FindControl("ddlType");
            OleDbConnection Conn = new OleDbConnection();
            Conn.ConnectionString = System.Configuration.ConfigurationManager.AppSettings["ConnectionString"];
            Conn.Open();

            // Populate the dropdown list for the phone types column
            String lcSQL = "SELECT Lu_Desc, iDtl_id FROM Lookup_dtl WHERE iHdr_id = 1";
            OleDbDataAdapter daTypes = new OleDbDataAdapter(lcSQL, Conn);
            DataSet dsTypes = new DataSet();
            daTypes.Fill(dsTypes);
            ddl.DataSource = dsTypes;
            ddl.DataTextField = "lu_desc";
            ddl.DataValueField = "iDtl_id";
            ddl.DataBind();
        }
But it is failing on this line:

DropDownList ddl = (DropDownList)e.Row.FindControl("ddlType");


ddl is null. But is I run the form without trying to populate the dropdown list, an empty dropdownlist shows up in the grid column, so I know it is there.

Any ideas?
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform