This is a migrated thread and some comments may be shown as answers.

RadGrid WebUserControl Edit Form

3 Answers 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mitchell
Top achievements
Rank 1
Mitchell asked on 25 Jun 2010, 01:21 PM
Hey Guys,

I'm using a WebUserControl as an Edit / Insert form for my RadGrid. I am populating this form programattically through each control's PreRender event. My problem is that when i load the form for an Insert instead of an edit, the form still tries to populate each control. Is there a better place for me to be binding this information? or is there a way that i can tell if the form was loaded either from an insert or a delete?

EDIT: Also, i've tried using

<%# Not (TypeOf DataItem Is Telerik.Web.UI.GridInsertionObject) %>

on the page, but i keep getting a "Name 'DataItem' is not declared"

Any help is appreciated. Thanks in advance,
Mitch

3 Answers, 1 is accepted

Sort by
0
Tsvetoslav
Telerik team
answered on 28 Jun 2010, 02:23 PM
Hello Mitchell,

Before binding the insert form you need to pass a collection of default values for the controls so that no "invalid cast" exception is thrown. More information you can find in the following help article in the paragraph Setting pre-defined values for different column editors:
http://www.telerik.com/help/aspnet-ajax/grdinsertingvaluesinplaceandeditforms.html

Regards,
Tsvetoslav
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Scott Smith
Top achievements
Rank 1
answered on 27 Aug 2010, 03:01 PM
That example doesn't seem relavant for me - I'm using complex binding for my grid - LLBLGen EntityCollection to be specific.  I'm not persisiting the data source in the viewstate or in session - it's retrieved from a WCF when it's needed (I'm using the NeedDataSource event of the grid).

I'm unsure how to get around this using the code in the example because it's using a viewstate-based DataTable/DataSet-based data source.

I have the update working fine - how would I tell my user control that it's dealing with a new complex entity object rather than updating an existing one?
0
Scott Smith
Top achievements
Rank 1
answered on 27 Aug 2010, 04:28 PM
I fixed this myself for anyone interested.

Since I'm using complex binding, I handle everything myself.  In the user control I simply check the DataItem property to see if it's a valid object to pull values from:

if (DataItem is ReconConfigAdjustmentEntity)
{
    // code here to pre-populate the controls on the user control
    // (ReconConfigAdjustmentEntity is my custom object
}

That's all it really took - I just needed to bypass the presetting of the values in my load method if the DataItem wasn't what I was expecting.  The grid page still pulls the data from the user control in the same exact manner, I just have to make sure to create a new object and set any values not coming from the user control.

Thanks
Tags
Grid
Asked by
Mitchell
Top achievements
Rank 1
Answers by
Tsvetoslav
Telerik team
Scott Smith
Top achievements
Rank 1
Share this question
or