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

Radgrid Default Date in Batch Editmode

8 Answers 121 Views
Input
This is a migrated thread and some comments may be shown as answers.
Rick
Top achievements
Rank 1
Rick asked on 20 Mar 2015, 11:07 PM
I have a radgrid that is set to batch editmode with edittype of "cell"

When I hit the addrecord button I want a date column to default to today's date.

Anyone have an example?

Thanks,

8 Answers, 1 is accepted

Sort by
0
Eyup
Telerik team
answered on 25 Mar 2015, 12:20 PM
Hi Rick,

You can use the following approach to achieve this requirement:
protected void RadGrid1_DataBinding(object sender, EventArgs e)
{
    GridDateTimeColumn col = RadGrid1.MasterTableView.GetColumn("OrderDate") as GridDateTimeColumn;
    col.DefaultInsertValue = DateTime.Now.ToShortDateString();
}

Hope this helps.

Regards,
Eyup
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Rick
Top achievements
Rank 1
answered on 25 Mar 2015, 03:09 PM
I tried your solution but it did not work.

This is the grid when the page opens
1
This is the grid after I hit the 'Add new record' button.
 It is here that I want to display the current date.












0
Rick
Top achievements
Rank 1
answered on 25 Mar 2015, 03:16 PM
With gif of screen prints
0
Eyup
Telerik team
answered on 30 Mar 2015, 10:58 AM
Hi Rick,

I've created a sample RadGrid web site to demonstrate that the suggested approach works as expected. Can you please run the attached application and let me know about the result on your side?

Regards,
Eyup
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
0
Rick
Top achievements
Rank 1
answered on 30 Mar 2015, 04:54 PM
When I changed my column from a string template column to a datetime column it worked.

Now my problem is that the insert to my table no longer works although my update to the same table does work.

Here are the insert and update statements                        
InsertCommand= " Insert into tasks (Date_Entered ,TaskType_ID , Originator_ID,Owner_ID ,Complete,Task ,Teststand_ID) values(@Date_Entered ,@Tasktype_ID,@Originator_ID, @Owner_ID,0,@Task,@teststand_ID)" 
 
UpdateCommand=" Update tasks set Date_Entered= @Date_Entered ,TaskType_ID =@TaskType_ID , Originator_ID =@Originator_ID,Owner_ID = @Owner_ID ,Complete = @Complete,Task=@Task where Task_ID =@Task_ID">












0
Rick
Top achievements
Rank 1
answered on 30 Mar 2015, 04:55 PM
Here are my params...
                        <InsertParameters>
                            <asp:Parameter Name="Tasktype_ID" Type="Int32" />
                            <asp:Parameter Name="Date_Entered" Type="Datetime" />
                            <asp:Parameter Name="Originator_ID" Type="Int32" />
                            <asp:Parameter Name="Owner_ID" Type="Int32" />
                            <asp:Parameter Name="Task" Type="String" />
                            <asp:ControlParameter ControlID="ComboPLCTestStand" DefaultValue="3" Name="teststand_ID" PropertyName="SelectedValue" />
                        </InsertParameters>
                         <UpdateParameters>
                           <asp:Parameter Name="Tasktype_ID" Type="Int32" />
                            <asp:Parameter Name="Date_Entered" Type="Datetime" />
                            <asp:Parameter Name="Originator_ID" Type="Int32" />
                            <asp:Parameter Name="Owner_ID" Type="Int32" />
                            <asp:Parameter Name="Task" Type="String" />
                            <asp:Parameter Name="Task_ID"  Type="Int32"/> 
                            <asp:Parameter Name="Complete" type="Boolean"/> 
                        </UpdateParameters>
0
Rick
Top achievements
Rank 1
answered on 30 Mar 2015, 05:20 PM
This insert with hardcoded date works....

InsertCommand= " Insert into tasks (Date_Entered ,TaskType_ID , Originator_ID,Owner_ID ,Complete,Task ,Teststand_ID) values('03/25/2015' ,@Tasktype_ID,@Originator_ID, @Owner_ID,0,@Task,@teststand_ID)" 
0
Eyup
Telerik team
answered on 02 Apr 2015, 11:25 AM
Hi Rick,

Could you verify whether the field is of type DateTime in your database? Also, does editing work with the modified configuration?

Alternatively, you can bring back the previous column and set the default value manually using the changeCellValue method:
http://www.telerik.com/help/aspnet-ajax/grid-batch-editing.html

Regards,
Eyup
Telerik
 

See What's Next in App Development. Register for TelerikNEXT.

 
Tags
Input
Asked by
Rick
Top achievements
Rank 1
Answers by
Eyup
Telerik team
Rick
Top achievements
Rank 1
Share this question
or