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

Manipulating data server side during grid automatic updates

2 Answers 110 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 2
DasNugget asked on 24 Jan 2009, 12:29 AM
I have a radgrid bound to a declarative datasource. 
The grid uses automatic updates, inserts, and deletes
with a popup edit form based on a two-way databinding
form template.  The code-behind subscribes to the
ItemUpdated,ItemDeleted, and ItemInserted events
to check for automatic operation exceptions and forward
those on to the user / master page gui.

After the user clicks the insert or update button, I want
to cross-check the entries from the edit form and pehaps
maniputate them.  Such as if a user enters a value over
some server-calculated maximum it would then simply
set the value to the maximum and allow the update to
continue.  I want to set the values of other fields that
the user cannot enter based on their entries.  I do not
want to trap these client-side before the server is hit
using validators.

What syntax would I use in the server-side codebehind
to access the user entries?   And in which server-side
events?   And how would I then manipulate the values
such that my updates overrode those of the user before
the database update is performed?

Thanks, Scott


2 Answers, 1 is accepted

Sort by
Top achievements
Rank 2
answered on 24 Jan 2009, 09:02 PM


Ok, I've come a long way on my own here.
In the UpdateCommand event, i cast the e.item to a GridEditFormItem
and that allows me access to the oldValues and newValues via the
item.ExtractValues.  All that works great but not if I want to tweak
the newValues before they are written to the database.
I can set one of the newValues, but the values going to the
database must be extracted before I get to tweak them, or
the ExtractValues is a one-time fetch of a copy of the
newValues only, and not used for the database update.
This forces me to use the last two lines of code, which
searches for the actual control on the edit form and
sets the value accordingly.  Is there a less combersome
way to SET the values that will go to the database?
Perhaps by passing my newValues back to the grid
some way?   It would be a bit cleaner, as my code
would be "findcontrol" free.




Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand





 If e.CommandName = RadGrid.UpdateCommandName Then





  If TypeOf (e.Item) Is GridEditFormItem Then

item As GridEditFormItem = CType(e.Item, GridEditFormItem)





    Dim oldValues = item.SavedOldValues




    Dim newValues = New System.Collections.Specialized.ListDictionary()





    Dim Ordered As Decimal = ToDec(newValues("Ordered"))





    Dim Received As Decimal = ToDec(oldValues("Received"))




   If Received >= Ordered Then newValues("ClosedFlag") = True Else newValues("ClosedFlag") = False 





    ' yea, i know, the whole ClosedFlag could simply be a calculated field in the SQL query...alas...not yet grasshopper
    Dim ClosedBox = CType(item.FindControl("ClosedFlagBox"), CheckBox)



    ClosedBox.Checked = newValues(






   End If





  End If





End Sub



Iana Tsolova
Telerik team
answered on 27 Jan 2009, 09:06 AM

Another option to achieve your goal would be to call the PerformUpdate() method of the GridTableView after changing the newValues array. Then you could miss the last If statement in your code.

Check it out and let me know if this works for you.

All the best,
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Asked by
Top achievements
Rank 2
Answers by
Top achievements
Rank 2
Iana Tsolova
Telerik team
Share this question