Csla->telerik radGrid binding on AddNew - ideas?

Csla->telerik radGrid binding on AddNew - ideas?

Old forum URL: forums.lhotka.net/forums/t/4251.aspx


mongo posted on Tuesday, January 29, 2008

I'm hoping someone can point me in the right direction.

I have a telerik grid (under ASP.NET) configured on my page setup along with a CslaDataSource configured to my BusinessListBase derived class.  This has one level of objects in a collection of BusinessBase objects- nothing fancy here.

When I click the "Add new item" item, I would hope that a new BusinessObject would get created and bound to for the initial value display.   I am hoping that I have the opportunity to load default values in the DataPortal. 

I am not seeing anything that sticks out - I tried overriding the AddNewCore() method on the collection to see if the grid was making a call but nothing came through.  I'm guessing I'm probably missing something obvious here.

Thank you,

-Steve

RockfordLhotka replied on Tuesday, January 29, 2008

Web data binding doesn't normally end up invoking AddNewCore(), because they don't use IBindingList.

Do you know what postback event occurs when you click "Add new item"? That is most likely where you'll need to put a bit of code to ask your collection for a new item - and you could call IBindingList yourself if that seems easiest - or implement some other public method on your collection that creates/adds a new item.

mongo replied on Tuesday, January 29, 2008

This makes perfect sense - an AddNew-style event is not readily apparent on the telerik control so I am pursuing this with telerik.  Once I have an approach, I'll post it here in case others are looking for the same behavior.

Thank you
-Steve

mongo replied on Wednesday, January 30, 2008

Thanks Rocky,

The telerik article that deals with this is located here: http://www.telerik.com/help/aspnet/grid/grdInsertingValuesInPlaceAndEditForms.html

If that link isn't available down the road, here is the general idea with Telerik:

There are two events on the grid that you can hook - InsertCommand and ItemCommand.  The easiest command to hook is ItemCreated because it's far less noisy than ItemCommand.  In InsertCommand, you can test to see if the item in question is being inserted (as opposed to editing a pre-existing object) and assign a new business object to it.  If you have an inline or form based edit, you will get this command fired once for each element being rendered.  If you are using a custom control, you will see this event fired once for the control.  If you are using a custom control, you must float the "public object DataItem" property on your control to get the data object assigned for binding purposes.

The code in the ItemCreated event looks something like this:

if( e.Item.OwnerTableView.IsItemInserted )
    e.Item.DataItem = MyBusinessObject.CreateNewObject(...);

You'll then need to adjust your CslaDataSource_UpdateObject(...) command to behave appropriately (insert vs. update).

Thanks again,

-Steve

mongo replied on Wednesday, January 30, 2008

I need to correct -

You do not need to modify UpdateObject event on your datasource to handle Inserts and Updates.  The InsertObject event will be properly raised.

Also,  the telerik Grid methods are ItemCreated and ItemCommand - as opposed to InsertCommand as I incorrectly stated earlier.

Copyright (c) Marimer LLC