I have two custom columns in an ASPxGridView which are bound to an in-memory data source independant of the gridviews datasource. Each custom column has an EditItemTemplate implementing the ITemplate interface. I can add/update and delete data using the gridview command controls.
My issue is:
I can't seem to locate the correct event handler to assign values to the EditItemTemplate controls whe a user edits the gridview row. The CellEditorInitialize event can't be used for custom editors. The controls within the editor are created at runtime based on data conditions and can be one of many DevExpress web editor controls.
Do I need to edit the custom ITemplate class to bind data to these controls so the controls have their correct unbound data values when editing? I am using the same ITemplate class for multiple gridviews and hence assigning values to the controls based on multiple detached datasources would be cumbersome.
The CellEditorInitialize event would have ben ideal in my situation.
Thanks.
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.
Hi,
I'll still wait for your comment but I managed to create an event handler in the ITemplate class that handles the databinding event for each control in the class.
void DateEditorBindingsEventHandler(object sender, EventArgs eventArgs)
{
GridViewDataItemTemplateContainer container = ((ASPxDateEdit)sender).NamingContainer as GridViewDataItemTemplateContainer;
((ASPxDateEdit)sender).Value = container.Text;
}
protected void AddDateEdit(ASPxGridView gv, Control container, String fieldName, String dataType, bool required, bool withTime)
{
ASPxDateEdit de = new ASPxDateEdit();
GridViewEditItemTemplateContainer editingContainer = (GridViewEditItemTemplateContainer)container;
int key = Convert.ToInt16(editingContainer.KeyValue);
de.ID = String.Format("{0}_{1}", fieldName, dataType);
if (withTime) { de.EditFormat = EditFormat.DateTime; }
if (required) { AddRequiredAttributes(de); }
de.DataBinding += new EventHandler(DateEditorBindingsEventHandler);
container.Controls.Add(de);
}
Hi Graham:
The CellEditorInitialize event is raised for the standard column editors only.
If you have a custom editor in a template container, then we recommend using its Init event.
The following article describes this approach in detail:
The general technique of using the Init/Load event handler
Thanks
Kate.
Hello,
I'm afraid the link provided in the answer does not satisfy my issue.
I cannot in-advance create the control init/load event handlers at design time because the controls are created at runtime.
I was successful in my implementation of creating handlers in my ITemplate based class but want to know if there exists other grid based API's like the CellEditorInitialize event to update the value of an editor control located within a custom column when the grid row is edited. When I assign a value to a custom column control, which event should be used in the ITemplate method body?
ASPxTextBox tb = new ASPxTextBox();
Hello Graham,
As Kate said, when you use custom templates, the grid won't raise the ASPxGridView.CellEditorInitialize event for them.
> When I assign a value to a custom column control, which event should be used in the ITemplate method body?
When you create an object, implementing the ITemplate interface, this doesn't mean that all controls are created. The method that can be interpreted as the ASPxGridView.CellEditorInitialize event handler is the InstantiateIn method of your template class, which is raised every time the grid creates template controls.
Thanks,
Vest
Hello,
I don't know if anyone is actually reading my comments but "I KNOW THE CELLEDITORINITIALIZE EVENT ISN'T RAISED"
None of the comments entered on this post have any value as they keep re-iterating the same information. As I've said, I successfully implemeted a custom Editor using the ITemplate interface so I know how to use it. I've already solved my issue and was looking for some "professional" guidance with the implementation of your API's.
Vest, Katy I can appreciate that you're probably answering the same questions day in and day out but perhaps reading and understanding the question should be the first tack rather than a generic copy/paste approach.
Please don't reply, as I'm afraid I'll just see another comment on the CellEditorInitialize event again.
Hello Graham,
As you didn't close the report, it is still active and requires my assistance. Please accept my sincere apologies for misunderstanding this thread. However, let me explain my last answer about the ITemplate interface.
Your initial question was:
My issue is:
I can't seem to locate the correct event handler to assign values to the EditItemTemplate controls whe a user edits the gridview row. The CellEditorInitialize event can't be used for custom editors. The controls within the editor are created at runtime based on data conditions and can be one of many DevExpress web editor controls.
As templates are provided by ASP.NET, the answer is related to how they should be used properly. There is an interesting article, which provides information that I gave you earlier: Understanding Templates in ASP.NET: Implementing ITemplate. You should use the InstantiateIn method to determine when controls are created.
> When I assign a value to a custom column control, which event should be used in the ITemplate method body?
This method is called the first during templates initialization. There you can assign a value to required controls. Of course, you can do it in all other events: Init, Load, DataBinding, etc. However, you should always remember that the ASP.NET Page LifeCycle differs from a control life cycle, which is created at runtime. For example, when the page loads its ViewState and post data, this doesn't mean that your control will load them too. If you create a control (for example) in the PreRender event handler, of course, it won't have any post data.
If you still need any further assistance on this item, please feel free to send us your project. We'll examine and fine-tune it.
Thanks,
Vest
Oops, forgot about closing this. Hope it doesn't affect your performance metrics.
BTW, your site is a wealth of information. Thank you for doing a fantastic job supporting your product(s)