Changing values before update

13 posts, 0 answers
  1. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 20 Oct 2008 Link to this post

    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
  2. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 21 Oct 2008 Link to this post

    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...
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 21 Oct 2008 Link to this post

    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
  5. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 21 Oct 2008 Link to this post

    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.
  6. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 21 Oct 2008 Link to this post

    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.
  7. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 21 Oct 2008 Link to this post

    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...
  8. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 21 Oct 2008 Link to this post

    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.
  9. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 23 Oct 2008 Link to this post

    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"??
  10. Steve Newbery
    Steve Newbery avatar
    103 posts
    Member since:
    Apr 2005

    Posted 23 Oct 2008 Link to this post

    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     
     
  11. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 23 Oct 2008 Link to this post

    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.
  12. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Oct 2008 Link to this post

    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.
  13. Erik
    Erik avatar
    314 posts
    Member since:
    Feb 2008

    Posted 23 Oct 2008 Link to this post

    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?
  14. Iana Tsolova
    Admin
    Iana Tsolova avatar
    3388 posts

    Posted 23 Oct 2008 Link to this post

    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.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017