Problems with dynamically created GridView/DetailsView

Discussion in 'ASP .Net Web Controls' started by Martin Simard, Apr 3, 2006.

  1. Hello there,

    I have some problems when trying to create dynamically (in code behind) a
    GridView and DetailsView. Both datasources of the controls are
    ObjectDataSource objects.

    First problem, when I run my page I got the following error when I click the
    "Edit" button in the DetailsView: The DetailsView 'DetailsView' fired event
    ModeChanging which wasn't handled (why?)

    I then create the corresponding handler, but the DetailsView refuses to get
    in EditMode. I have to add the following code in the handler:
    detailsControl.ChangeMode(e.NewMode); I can now edit my field values, but
    other problems follow.

    When I click the UpdateButton, it fires the ItemUpdating event handler of my
    DetailsView, but the DetailsViewUpdateEventArgs contains nothing. No
    NewValues, no OldValues... just empty.

    I'm a little bit confused now, since everything works fine when I create the
    same page at design time dragging and dropping the
    GridView/DetailsView/ObjectDataSource and setting the properties/events.
    Both pages contain the same controls, same properties, but different

    Maybe I'm missing something in dynamic controls creation. I tried to create
    my controls in the Page.OnPreInit and the Page.CreateChildControls methods.
    My databings are done in the Page.PreRender method. I tried severals things,
    and nothings seems to work. DataBinding problem? ViewState?

    Any idea someone?
    Martin Simard, Apr 3, 2006
    1. Advertisements

  2. When I say "dynamically created", I mean that it is a composite control. My
    control inherits from WebControl and all controls in it (including the
    GridView and the DetailsView) are created programmatically.
    Martin Simard, Apr 3, 2006
    1. Advertisements

  3. Martin Simard

    Grim Guest

    I'm running into the same problem. Have you resolved this Martin?
    Grim, Apr 20, 2006
  4. Hi Grim,

    I have not resolved this yet. Unfortunately, I put this on hold for a few

    But I'm still looking for a solution. Our web applications are actually
    designed to generate webcontrols on the fly (under VS 2005 .NET 1.1). We
    developed a lot of composite controls in a few class libraries which are
    reused in different web applications (create dynamically on web forms).

    Since then, I looked at the following topic to find new ways of designing
    reusable webforms and webcontrols:

    Anyway, we're looking forward to port our actual applications under VS 2005
    / .NET 2.0 and use the new controls and we're still facing the problem
    described under.

    I hope someone has a solution (or at least a hint) for us.

    Martin Simard, Apr 25, 2006
    1. Advertisements

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.