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

Changing values before update

12 Answers 390 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Erik
Top achievements
Rank 2
Erik asked on 20 Oct 2008, 02:35 PM
Hi,

I've been working with the grid now for a week, nice features!

I have a grid with popup editing. I changed the edit template, but had some problems with the radcombo, because of faulty data. Therefore i do not bind the radcombo (i.e. bind("ArtDesc") ), but use the eval.

In a FormView i can use the e.NewValues("ArtDesc") = "Erik" in the event "FormView_ItemUpdating"

I can not find that functionality in the radgrid? Is the following link REALY the only way ??

http://demos.telerik.com/aspnet/prometheus/Grid/Examples/DataEditing/ExtractValues/DefaultVB.aspx

12 Answers, 1 is accepted

Sort by
0
Erik
Top achievements
Rank 2
answered on 21 Oct 2008, 09:28 AM
Telerik support, can you provide me with an answer? I have the same situation now in 7 grids and linke an answer before going any along, so the project is stagnating...
0
Shinu
Top achievements
Rank 2
answered on 21 Oct 2008, 10:35 AM
Hi,

You can access the RadCombobox in the Update Command as shown in the code below. The
CS:
protected void RadGrid2_UpdateCommand(object source, GridCommandEventArgs e) 
        { 
             
            GridEditableItem editedItem = (GridEditableItem)e.Item; 
            string strValue = ((RadComboBox)(editedItem["ProductName"].Controls[0])).SelectedValue; 
        } 

Also check out the link below:
http://demos.telerik.com/aspnet/prometheus/Grid/Examples/DataEditing/UserControlEditForm/DefaultVB.aspx


Thanks,
Shinu
0
Erik
Top achievements
Rank 2
answered on 21 Oct 2008, 11:30 AM
Thanks for your reply, but that is not what i mean;

In your example you show how to read a value from a databound control, instead i want to SET the value.

for i.e. when writing a record, the field "ChangeBy" must be filled with the current user name. In FormView you can set the newvalues("Fieldname") in the "FormView_ItemUpdating"

Q: How do i manage this in a grid editing template.
0
Iana Tsolova
Telerik team
answered on 21 Oct 2008, 11:52 AM
Hi Proovit,

The selected value of the combobox would be available in the extracted values collection in case you bind it with the two-way binding method, e.g. Bind(). Otherwise you can try the suggestion that Shinu provided. 

Let me know if any issues arise.
 
Regards,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erik
Top achievements
Rank 2
answered on 21 Oct 2008, 12:23 PM
Thanks Iana for your reply,

It seems a simple question...

The suggestion shinu made, does not provide a aolution because i can't SET the new value, i can only RETRIEVE it.

Binding (Bind("") ) is no solution, because it is NOT a fill-in field, its a auto updated field.

I just want to set a database field to a value, in code, in a grid event, the field is hidden in de editform. bacause the user is not allowed to set it, the application must provide it, a client id for i.e. or a Changed Date.

hope this clarifies my question...
0
Iana Tsolova
Telerik team
answered on 21 Oct 2008, 02:58 PM
Hello Proovit,

Thank you for providing details.

Please try setting the ForceExtractValues property of the problematic template column to true and set its DataField property accordingly. Then you can handle the UpdateCommand event of the grid and do the same as in the RowUpdating event handler of the GridView.

Check it out and let me know how it goes.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erik
Top achievements
Rank 2
answered on 23 Oct 2008, 12:01 PM
I spend hours trying different ways, but still no solution...

I think we are talking in circles, so i'm changing tactics.. ;-)

A user logs in. By his account the system knows he is from the company "PROOVIT". So, orders inserted by him must, whem saved, also save the client ID.

So after he fills in his order, he presses the "Save" button. Then we come in the UpdateCommand event:

    Protected Sub RadGrid1_UpdateCommand(ByVal source As ObjectByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles RadGrid1.UpdateCommand  
        Dim editedItem As GridEditableItem = DirectCast(e.Item, GridEditableItem)  
 
        Dim gdi As GridDataItem  
        Dim ite As GridEditableItem  
 
        For Each gdi In RadGrid1.EditItems  
            If gdi.OwnerTableView.EditMode = GridEditMode.InPlace Then 
                ite = CType(gdi, GridEditableItem)  
            Else 
                ite = CType(gdi.EditFormItem, GridEditableItem)  
            End If 
        Next 
 
        ' How to set CLIENT_ID  
        editedItem("CLIENT_ID").Text = "PROOVIT" 
 
    End Sub 
 
I found some code, for example.

Now, the question is: HOW do I update the column "CLIENT_ID" with the value "PROOVIT"??
0
Steve Newbery
Top achievements
Rank 1
answered on 23 Oct 2008, 12:40 PM
Proovit, I do this by just setting the default value of the UpdateParameter for the datasource:

     Protected Sub RadGrid1_UpdateCommand(ByVal source As Object, ByVal e As GridCommandEventArgs)     
        If Page.IsValid Then                 
            SqlDataSource1.UpdateParameters("CLIENT_ID").DefaultValue = "proovit"    
        Else     
            e.Canceled = True    
        End If                
    End Sub     
 
0
Erik
Top achievements
Rank 2
answered on 23 Oct 2008, 12:50 PM
thanks, thought about that in other matters.

How would you update a field "ModifyDate" on a Edit/Update ? A default value will not work because the value is set to an older date.
0
Iana Tsolova
Telerik team
answered on 23 Oct 2008, 01:08 PM
Hi Proovit,

You can handle the ItemDataBound event of your grid and then change the "ModifyDate" field with the following code for instance:

Protected Sub RadGrid1_ItemDataBound(ByVal sender As ObjectByVal e As GridItemEventArgs)  
    If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode AndAlso Not e.Item.OwnerTableView.IsItemInserted Then 
        Dim editedItem As GridEditableItem = TryCast(e.Item, GridEditableItem)  
        Dim modifyDate As TextBox = TryCast(editedItem("ModifyDate").FindControl("txtModifyDate"), TextBox)  
        modifyDate.Text = DateTime.Now.ToString()  
    End If 
End Sub 


Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Erik
Top achievements
Rank 2
answered on 23 Oct 2008, 01:46 PM

ok, your code generated an error because findcontrol failed. A bit curious, because the control si there.. but I changed it to:

CType(e.Item.FindControl("txtModifyDate"), TextBox).Text = DateTime.Now.ToString() 

And this works.

Last question:
How can i set a value after the user clickes the save button, but before the save is realy executed?
0
Iana Tsolova
Telerik team
answered on 23 Oct 2008, 02:44 PM
Hello Proovit,

This could be done on UpdateCommand event.
Find more about handling RadGrid UpdateCOmmand in the follwoing resource:
http://www.telerik.com/help/aspnet-ajax/grdupdatinginplaceandeditforms.html
http://www.telerik.com/help/aspnet-ajax/grdupdatingvaluesusercontrolformtemplate.html

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Erik
Top achievements
Rank 2
Answers by
Erik
Top achievements
Rank 2
Shinu
Top achievements
Rank 2
Iana Tsolova
Telerik team
Steve Newbery
Top achievements
Rank 1
Share this question
or