dropDownList control not accessible inside dataGrid

Discussion in 'ASP .Net' started by steven, May 12, 2008.

  1. steven

    steven Guest

    i've got a dropDownList that I'm trying to populate from my code
    behind as follows:

    uxVehicleColourEdit.DataSource = oDsLookups.Tables["COLOR"];

    if the dropDown is placed inside a datagrid, i get compile time errors
    stating the control doesn't exist in the current content:

    <asp:DataGrid ID="tmp" runat="server">
    <Columns>
    <asp:TemplateColumn>
    <EditItemTemplate>
    <asp:DropDownList ID="uxVehicleColourEdit" runat="server"></
    asp:DropDownList>
    </EditItemTemplate>
    </asp:TemplateColumn>
    </Columns>
    </asp:DataGrid>

    if i move uxVehicleColourEdit outside the datagrid, i get no compile
    errors.

    any ideas what's going on?

    tks
    steven, May 12, 2008
    #1
    1. Advertising

  2. When you populate the grid, it will likely have more than one record. Each
    record will include it's own ddl. That's why you can't access a single ddl
    by id.

    You need to handle ItemDataBound event for the grid. In the event use
    e.Item.FindControl("uxVehicleColourEdit") to get a reference to the ddl.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "steven" <> wrote in message
    news:...
    > i've got a dropDownList that I'm trying to populate from my code
    > behind as follows:
    >
    > uxVehicleColourEdit.DataSource = oDsLookups.Tables["COLOR"];
    >
    > if the dropDown is placed inside a datagrid, i get compile time errors
    > stating the control doesn't exist in the current content:
    >
    > <asp:DataGrid ID="tmp" runat="server">
    > <Columns>
    > <asp:TemplateColumn>
    > <EditItemTemplate>
    > <asp:DropDownList ID="uxVehicleColourEdit" runat="server"></
    > asp:DropDownList>
    > </EditItemTemplate>
    > </asp:TemplateColumn>
    > </Columns>
    > </asp:DataGrid>
    >
    > if i move uxVehicleColourEdit outside the datagrid, i get no compile
    > errors.
    >
    > any ideas what's going on?
    >
    > tks
    Eliyahu Goldin, May 12, 2008
    #2
    1. Advertising

  3. steven

    Stan Guest

    On 12 May, 15:59, "Eliyahu Goldin"
    <> wrote:
    > When you populate the grid, it will likely have more than one record. Each
    > record will include it's own ddl. That's why you can't access a single ddl
    > by id.
    >
    > You need to handle ItemDataBound event for the grid. In the event use
    > e.Item.FindControl("uxVehicleColourEdit") to get a reference to the ddl.
    >
    > --
    > Eliyahu Goldin,
    > Software Developer
    > Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
    >
    > "steven" <> wrote in message
    >
    > news:...
    >
    >
    >
    > > i've got a dropDownList that I'm trying to populate from my code
    > > behind as follows:

    >
    > > uxVehicleColourEdit.DataSource = oDsLookups.Tables["COLOR"];

    >
    > > if the dropDown is placed inside a datagrid, i get compile time errors
    > > stating the control doesn't exist in the current content:

    >
    > > <asp:DataGrid ID="tmp" runat="server">
    > > <Columns>
    > > <asp:TemplateColumn>
    > > <EditItemTemplate>
    > > <asp:DropDownList ID="uxVehicleColourEdit" runat="server"></
    > > asp:DropDownList>
    > > </EditItemTemplate>
    > > </asp:TemplateColumn>
    > > </Columns>
    > > </asp:DataGrid>

    >
    > > if i move uxVehicleColourEdit outside the datagrid, i get no compile
    > > errors.

    >
    > > any ideas what's going on?

    >
    > > tks- Hide quoted text -

    >
    > - Show quoted text -


    Not quite Eliyahu. The dropdownlist is in the EditItem template (as it
    should be) so will only occur in the row that is placed in edit mode
    when an edit command is issued. The event to use for the assignment is
    EditCommand.

    BTW steven is there any reason you are using DataGrid rather than
    GridView? Or are you constrained to use ASP.NET v 1?

    ASP.NET v 2 would make the task easier because you could bind the ddl
    to an appropriate DataSource object using the DatasourceID property.
    By placing the both the ddl and the datasource control inside the
    EditItemtemplate it would load itself without any code.
    Stan, May 12, 2008
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DC Gringo
    Replies:
    4
    Views:
    4,805
    mfreidge
    Dec 17, 2007
  2. vunet
    Replies:
    2
    Views:
    598
    vunet
    Dec 10, 2007
  3. Cathy

    Dynamically Added User Control not accessible!

    Cathy, Dec 16, 2003, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    116
    Cathy
    Dec 16, 2003
  4. DC Gringo
    Replies:
    3
    Views:
    203
    DC Gringo
    Sep 14, 2004
  5. Replies:
    1
    Views:
    198
Loading...

Share This Page