dropDownList control not accessible inside dataGrid

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steven

    dropDownList control not accessible inside dataGrid

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

    uxVehicleColour Edit.DataSource = oDsLookups.Tabl es["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:TemplateCo lumn>
    <EditItemTempla te>
    <asp:DropDownLi st ID="uxVehicleCo lourEdit" runat="server"> </
    asp:DropDownLis t>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    </Columns>
    </asp:DataGrid>

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

    any ideas what's going on?

    tks
  • Eliyahu Goldin

    #2
    Re: dropDownList control not accessible inside dataGrid

    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.FindCont rol("uxVehicleC olourEdit") to get a reference to the ddl.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]




    "steven" <s_mumby@hotmai l.comwrote in message
    news:1f19e0a5-9074-4b26-967a-ee1233c1f6e0@8g 2000hse.googleg roups.com...
    i've got a dropDownList that I'm trying to populate from my code
    behind as follows:
    >
    uxVehicleColour Edit.DataSource = oDsLookups.Tabl es["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:TemplateCo lumn>
    <EditItemTempla te>
    <asp:DropDownLi st ID="uxVehicleCo lourEdit" runat="server"> </
    asp:DropDownLis t>
    </EditItemTemplat e>
    </asp:TemplateCol umn>
    </Columns>
    </asp:DataGrid>
    >
    if i move uxVehicleColour Edit outside the datagrid, i get no compile
    errors.
    >
    any ideas what's going on?
    >
    tks

    Comment

    • Stan

      #3
      Re: dropDownList control not accessible inside dataGrid

      On 12 May, 15:59, "Eliyahu Goldin"
      <REMOVEALLCAPIT ALSeEgGoldD...@ mMvVpPsS.orgwro te:
      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.FindCont rol("uxVehicleC olourEdit") to get a reference to the ddl.
      >
      --
      Eliyahu Goldin,
      Software Developer
      Microsoft MVP [ASP.NET]http://msmvps.com/blogs/egoldinhttp://usableasp.net
      >
      "steven" <s_mu...@hotmai l.comwrote in message
      >
      news:1f19e0a5-9074-4b26-967a-ee1233c1f6e0@8g 2000hse.googleg roups.com...
      >
      >
      >
      i've got a dropDownList that I'm trying to populate from my code
      behind as follows:
      >
      uxVehicleColour Edit.DataSource = oDsLookups.Tabl es["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:TemplateCo lumn>
      <EditItemTempla te>
      <asp:DropDownLi st ID="uxVehicleCo lourEdit" runat="server"> </
      asp:DropDownLis t>
      </EditItemTemplat e>
      </asp:TemplateCol umn>
      </Columns>
      </asp:DataGrid>
      >
      if i move uxVehicleColour Edit 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
      EditItemtemplat e it would load itself without any code.

      Comment

      Working...