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

Set Custom Data/Override Data With EntityDataSource and AllowAutomaticUpdates

4 Answers 35 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Peter
Top achievements
Rank 1
Peter asked on 06 Dec 2012, 08:30 AM
I have a RadGrid with using AllowAutomaticUpdates and EntityDataSource and I'd like to set some custom data (or override data) before the item is saved.

How do I do this?

I've tried this, but it doesn't work:

protected void rgUnits_UpdateCommand(object sender, GridCommandEventArgs e)
       {
           GridEditableItem item = (GridEditableItem)e.Item;
           ((RadDatePicker)item["LastModified"].Controls[0]).SelectedDate = DateTime.Now; 
           ((TextBox)item["LastModifiedBy"].Controls[0]).Text = Context.User.Identity.Name;
       }

<telerik:GridDateTimeColumn DataField="LastModified" FilterControlAltText="Filter Last Modified" HeaderText="Last Modified" SortExpression="LastModified" UniqueName="LastModified" ReadOnly="true" AllowFiltering="true" ColumnEditorID="gceSmallDateBox" DataFormatString="{0:dd/MM/yyyy}" PickerType="DatePicker">
                                            </telerik:GridDateTimeColumn>
                                            <telerik:GridBoundColumn DataField="LastModifiedBy" FilterControlAltText="Filter Last Modified By" HeaderText="Last Modified By" SortExpression="LastModifiedBy" UniqueName="LastModifiedBy" ReadOnly="true" AllowFiltering="true">
                                            </telerik:GridBoundColumn>


I don't *need* to have them as Grid Columns, but I figured this is what I'd have to do to get it work.

4 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 06 Dec 2012, 09:17 AM
Hi.

Since you are setting ReadOnly property for the columns, the column editor will not be rendered in edit mode. Try setting it as false and then set the selected date. Hope this helps.

Thanks,
Shinu.
0
Peter
Top achievements
Rank 1
answered on 07 Dec 2012, 01:07 AM
Thanks, this worked.

But I don't wan't these fields to be editable - is there another way to set additional/custom data before saving back to the EntityDataSource?

(For the time-being, I might just try display:none  in CCS, but it would be great to know how I can do custom stuff with Automatic Updates/Inserts).
0
Peter
Top achievements
Rank 1
answered on 10 Dec 2012, 03:00 AM
This post might have some detail on what I'm trying to achieve. I'll probably have a play with it.

(I want to have the Automatic Inserts/Updates for most things, but sometimes I may want to do something special etc).
0
Peter
Top achievements
Rank 1
answered on 10 Dec 2012, 03:14 AM
Ok, I think I worked it out - you can handle the EntityDataSource's Updating (or Inserting/Deleting etc.) event. e.g.

protected void MyDataSource_Updating(object sender, EntityDataSourceChangingEventArgs e)
        {
            MyEntity entity = ((MyEntity)e.Entity);
            entity.DataField = (new Random()).Next(100);
        }

This is what I've been looking for, for awhile. Glad to have found it!

This post could also be important if there's missing values in the Entity.
Tags
Grid
Asked by
Peter
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Share this question
or