Ticket T306397
Visible to All Users

ASPxGridView - How to add a custom control to EditFormLayout for an unbound column

created 9 years ago (modified 9 years ago)

I'm testing out the new EditFormLayout property on a new project. As part of this project, we are editing a list of objects with various properties. When our users edit these records, we want to force them to provide a reason for the change. However, it doesn't make sense semantically to include the change reason in the underlying data object, as it would only apply to the update, not to the actual object that we'd be showing on the gridview.

Here is my current EditFormLayout section.

ASPx
<EditFormLayoutProperties ColCount="1" > <Items> <dx:GridViewColumnLayoutItem ColumnName="A"> </dx:GridViewColumnLayoutItem> <dx:GridViewColumnLayoutItem ColumnName="B"> </dx:GridViewColumnLayoutItem> <dx:GridViewColumnLayoutItem ColumnName="C"> </dx:GridViewColumnLayoutItem> <dx:GridViewColumnLayoutItem ColumnName="D"> </dx:GridViewColumnLayoutItem> <dx:GridViewColumnLayoutItem ColumnName="E"> </dx:GridViewColumnLayoutItem> <dx:GridViewColumnLayoutItem Caption="Change Reason" VerticalAlign="Top"> <Template> <uc1:MyCustomControls runat="server" id="MyCustomControl" /> </Template> </dx:GridViewColumnLayoutItem> <dx:EditModeCommandLayoutItem ShowUpdateButton="True" ShowCancelButton="True" HorizontalAlign="Center"> </dx:EditModeCommandLayoutItem> </Items> </EditFormLayoutProperties>

I've tried using two-way binding to try to get the MyCustomControl control to appear in the ASPxDataUpdatingEventArgs event values, but no dice. I got an error that basically translated to the fact that the attempted property doesn't exist in the underlying datasource, which makes sense.

ASPx
<dx:GridViewColumnLayoutItem Caption="Change Reason" VerticalAlign="Top"> <Template> <uc1:MyCustomControls runat="server" id="MyCustomControl" Value='<%# Bind("MyCustomControlId") %>' /> </Template> </dx:GridViewColumnLayoutItem>

Is there any way to achieve what I'm looking to do? Essentially I'd be building the object that I'm updating from the event args, then passing that and the reason id to my dal layer to update the record and the reason.

Answers approved by DevExpress Support

created 9 years ago

Hello Marisa,

It is possible to implement this manually as follows:

  1. Use the Eval method for necessary editors inside your user control to bind the editor's initial value;
  2. Use the newly-implemented FindEditFormLayoutItemTemplateControl method (ASPxGridView - Provide a method that allows finding template controls inside EditFormLayoutProperties.Items.GridViewColumnLayoutItem.Template) in the grid's RowUpdatingRowInserting event handlers to find your editors and obtain their value.
    Comments (2)
    M M
    Marisa W. Smith 9 years ago

      Unfortunately I can't confirm that this is the solution; in order to get the FindEditFormLayoutItemTemplateControl method I downloaded the hotfix which was provided in the link you provided. However, within that hotfix there appears to be an issue with how compound primary keys are handled in GridViews. I've attached a project which demonstrates this issue. The project is currently upgraded to that hotfix revision and will fail with the first call, but succeed on the second. If you downgrade it to the vanilla 15.1 or to 14.7, it will succeed.

      DevExpress Support Team 9 years ago

        Hello,

        To process your recent post more efficiently, I created a separate ticket on your behalf: T307337: ASPxGridView - "Object reference not set to an instance of an object" error when a complex KeyFieldName is used. This ticket is currently in our processing queue. Our team will address it as soon as we have any updates.

        Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

        Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.