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

Insert today's date when updating popup form

3 Answers 93 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Clive Hoggar
Top achievements
Rank 1
Clive Hoggar asked on 29 Dec 2008, 01:46 PM
Hi
I am using radgrid with the automatically generated popup edit form.
One of the fields displays the 'Last_Edit' date recorded in the database.
When the edit form 'UPDATE' link is clicked I want to save the current date instead of the
database value.
How can I best do this? 

Thanks for you help!

Clive

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 29 Dec 2008, 02:08 PM
Hello Clive,

I suppose you are using a DateTimeColumn for displaying Last_Edit date. If that is the case, you can access the DatePicker in the UpdateCommand and then set its date as shown below:
cs:
protected void RadGrid1_UpdateCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.Item is GridEditableItem && e.Item.IsInEditMode) 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            RadDatePicker datepicker = (RadDatePicker)item["Last_Edit"].Controls[0]; 
            datepicker.SelectedDate = System.DateTime.Today; 
            //update query 
        } 
    } 

Thanks
Princy.
0
Clive Hoggar
Top achievements
Rank 1
answered on 29 Dec 2008, 03:35 PM
Hi
I don't have a date picker control anywhere yet. Where do I insert this?
thanks
Clive
0
Dimo
Telerik team
answered on 29 Dec 2008, 04:08 PM
Hi Clive,

Well, no matter what control you are using to enter a value for the "Last_Edit" field (e.g. a textbox), you can set its value to DateTime.Now() at runtime (as demonstrated by Shinu) and even make the control read-only, so that the value cannot be changed by the user.

Alternatively, you can use the RadGrid's ItemCommand event handler to add DateTime.Now() to the respective field after the user has submitted the edit form. However, this approach is different depending on your datasource and the way RadGrid is databound, so if you want to implement this, please provide more information.

All the best,
Dimo
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
Clive Hoggar
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Clive Hoggar
Top achievements
Rank 1
Dimo
Telerik team
Share this question
or